mic*_*ael 148 git version-control git-rewrite-history
我做了3个git提交,但没有被推送.如何修改不是最新的旧版本(ddc6859af44)和(47175e84c)?
$git log
commit f4074f289b8a49250b15a4f25ca4b46017454781
Date: Tue Jan 10 10:57:27 2012 -0800
commit ddc6859af448b8fd2e86dd0437c47b6014380a7f
Date: Mon Jan 9 16:29:30 2012 -0800
commit 47175e84c2cb7e47520f7dde824718eae3624550
Date: Mon Jan 9 13:13:22 2012 -0800
Run Code Online (Sandbox Code Playgroud)
Ada*_*ruk 189
git rebase -i HEAD^^^
Run Code Online (Sandbox Code Playgroud)
现在用edit
或e
(替换pick
)标记要修改的那些.现在保存并退出.
现在进行更改
git add -A
git commit --amend --no-edit
git rebase --continue
Run Code Online (Sandbox Code Playgroud)
如果要添加额外删除,请从commit命令中删除选项.如果要调整消息,请忽略该--no-edit
选项.
ako*_*nov 105
我准备好了我想用旧版本修改的提交,并且惊讶地看到rebase -i抱怨我有未提交的更改.但我不想再次指定旧提交的编辑选项进行更改.所以解决方案非常简单明了:
git rebase -i <commit you want to amend>^
- 注意^
这样你就可以在文本编辑器中看到所述提交你会得到像这样的东西:
pick 8c83e24 use substitution instead of separate subsystems file to avoid jgroups.xml and jgroups-e2.xml going out of sync
pick 799ce28 generate ec2 configuration out of subsystems-ha.xml and subsystems-full-ha.xml to avoid discrepancies
pick e23d23a fix indentation of jgroups.xml
Run Code Online (Sandbox Code Playgroud)现在要结合e23d23a和8c83e24你可以改变行顺序并使用像这样的壁球:
pick 8c83e24 use substitution instead of separate subsystems file to avoid jgroups.xml and jgroups-e2.xml going out of sync
squash e23d23a fix indentation of jgroups.xml
pick 799ce28 generate ec2 configuration out of subsystems-ha.xml and subsystems-full-ha.xml to avoid discrepancies
Run Code Online (Sandbox Code Playgroud)写入和退出文件,您将出现一个编辑器来合并提交消息.这样做并保存/退出文本文档
学分归于:http://git-scm.com/book/en/Git-Tools-Rewriting-History 还有其他有用的演示git魔法.
Ben*_*ier 13
您可以使用git rebase
来重写提交历史记录.这可能会对您的更改造成破坏,因此请谨慎使用.
首先将"修改"更改作为正常提交提交.然后从最早提交的父项开始执行交互式rebase
git rebase -i 47175e84c2cb7e47520f7dde824718eae3624550^
Run Code Online (Sandbox Code Playgroud)
这将启动所有提交的编辑器.对它们重新排序,以便您的"修改"提交低于您要修改的提交.然后使用"修改"提交替换行上的第一个单词s
,将其与之前的提交组合(s quash).保存并退出编辑器并按照说明操作.
Mel*_*ius 12
我已经用了几次另一种方式.实际上,它是一本手册git rebase -i
,当你想要重新排列几个提交包括挤压或拆分其中的一些时,它很有用.主要优点是您不必在一个时刻决定每个提交的命运.您还可以在此过程中使用所有Git功能,这与rebase期间不同.例如,您可以随时显示原始历史记录和重写历史记录,甚至可以进行其他修改!
我将通过以下方式引用提交,因此它易于阅读:
C # good commit after a bad one
B # bad commit
A # good commit before a bad one
Run Code Online (Sandbox Code Playgroud)
您在开始时的历史如下所示:
x - A - B - C
| |
| master
|
origin/master
Run Code Online (Sandbox Code Playgroud)
我们将以这种方式重新创建它:
x - A - B*- C'
| |
| master
|
origin/master
Run Code Online (Sandbox Code Playgroud)
git checkout B # get working-tree to the state of commit B
git reset --soft A # tell Git that we are working before commit B
git checkout -b rewrite-history # switch to a new branch for alternative history
Run Code Online (Sandbox Code Playgroud)
提高你的旧提交使用git add
(git add -i
,git stash
等等)现在.您甚至可以将旧提交分成两个或更多.
git commit # recreate commit B (result = B*)
git cherry-pick C # copy C to our new branch (result = C')
Run Code Online (Sandbox Code Playgroud)
中间结果:
x - A - B - C
| \ |
| \ master
| \
| B*- C'
| |
| rewrite-history
|
origin/master
Run Code Online (Sandbox Code Playgroud)
让我们完成:
git checkout master
git reset --hard rewrite-history # make this branch master
Run Code Online (Sandbox Code Playgroud)
就是这样,你push
现在可以取得进步.
归档时间: |
|
查看次数: |
99417 次 |
最近记录: |