我在过去一小时内改变了一些事情,并一步一步地提交了它们,但我刚刚意识到我忘了在一些提交之前添加一个已更改的文件.
日志看起来像这样:
GIT TidyUpRequests u:1 d:0> git log
commit fc6734b6351f6c36a587dba6dbd9d5efa30c09ce
Author: David Klein <>
Date: Tue Apr 27 09:43:55 2010 +0200
The Main program now tests both Webservices at once
commit 8a2c6014c2b035e37aebd310a6393a1ecb39f463
Author: David Klein <>
Date: Tue Apr 27 09:43:27 2010 +0200
ISBNDBQueryHandler now uses the XPath functions from XPath.fs too
commit 06a504e277fd98d97eed4dad22dfa5933d81451f
Author: David Klein <>
Date: Tue Apr 27 09:30:34 2010 +0200
AmazonQueryHandler now uses the XPath Helper functions defined in XPath.fs
commit a0865e28be35a3011d0b6091819ec32922dd2dd8 <--- changed file should go here
Author: David Klein <>
Date: Tue Apr 27 09:29:53 2010 +0200
Factored out some common XPath Operations
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
Gre*_*ill 600
使用git rebase
.特别:
git stash
存储您要添加的变化.git rebase -i HEAD~10
(或者你希望看到的许多提交).a0865...
通过pick
将行开头的单词更改为,将问题()中的提交标记为编辑edit
.不要删除其他行,否则会删除提交.[^ vimnote]git stash pop
git add <file>
.git commit --amend --no-edit
.git rebase --continue
会重写你的其余提交对新的提交.[^ vimnote]:如果您正在使用,vim
则必须Insert按键进行编辑,然后Esc键入:wq
以保存文件,退出编辑器并应用更改.或者,您可以配置一个用户友好的git的承诺编辑用git config --global core.editor "nano"
.
Joe*_*rra 284
要通过一个小的更改"修复"旧的提交,而不更改旧提交的提交消息,其中OLDCOMMIT
类似于091b73a
:
git add <my fixed files>
git commit --fixup=OLDCOMMIT
git rebase --interactive --autosquash OLDCOMMIT^
Run Code Online (Sandbox Code Playgroud)
您还可以使用git commit --squash=OLDCOMMIT
在rebase期间编辑旧的提交消息.
git rebase --interactive
将调出一个文本编辑器(可以配置)来确认(或编辑)rebase指令序列.文件中有关于rebase指令更改的信息; 只需保存并退出编辑器(:wq
invim
)继续使用rebase.--autosquash
将自动--fixup=OLDCOMMIT
按所需顺序进行任何提交.请注意,--autosquash
仅在使用该--interactive
选项时有效.^
中OLDCOMMIT^
意味着它是一个参考之前提交OLDCOMMIT
.上述步骤适用于验证和/或修改rebase指令序列,但也可以通过以下方式跳过/自动化交互式rebase文本编辑器:
GIT_SEQUENCE_EDITOR
为脚本.请参阅git commit和git rebase.与往常一样,当重写git历史记录时,您应该只修改或压缩尚未发布给其他任何人的提交(包括随机互联网用户和构建服务器).
kni*_*ttl 60
使用git 1.7,有一个非常简单的方法git rebase
:
暂存你的文件:
git add $files
Run Code Online (Sandbox Code Playgroud)
创建一个新的提交并重新使用"破坏"提交的提交消息
git commit -c master~4
Run Code Online (Sandbox Code Playgroud)
fixup!
在主题行中添加前缀(或者squash!
如果要编辑commit(message)):
fixup! Factored out some common XPath Operations
Run Code Online (Sandbox Code Playgroud)
用于git rebase -i --autosquash
修复您的提交
您可以尝试一个rebase --interactive
会话来修改您的旧提交(前提是您尚未将这些提交推送到另一个仓库).
有时在b.2中修复了这个问题.不能修改为它修复的不太完美的提交,因为该提交深深埋藏在补丁系列中.
这正是交互式rebase的用途:在大量的"a"和"b"之后使用它,通过重新排列和编辑提交,并将多个提交压缩成一个.使用您要保留的最后一次提交启动它:
git rebase -i <after-this-commit>
Run Code Online (Sandbox Code Playgroud)
编辑器将被激活当前分支中的所有提交(忽略合并提交),这些提交在给定的提交之后.
您可以将此列表中的提交重新排序到您的内容,然后您可以删除它们.该列表看起来或多或少像这样:
pick deadbee The oneline of this commit
pick fa1afe1 The oneline of the next commit
...
Run Code Online (Sandbox Code Playgroud)
在线描述纯粹是为了您的乐趣; git rebase不会查看它们,而是查看提交名称(本例中为"deadbee"和"fa1afe1"),因此不要删除或编辑名称.
通过使用命令"edit"替换命令"pick",您可以告诉git rebase在应用该提交后停止,以便您可以编辑文件和/或提交消息,修改提交并继续重新定位.
归档时间: |
|
查看次数: |
78955 次 |
最近记录: |