处理不同的git补丁?

时间:2015-02-14 00:25:29

标签: git

示例:我有一个仓库,我承诺;我有我的分支,我在一个功能上工作。 我使用--amend迭代对相同文件的更改。然后我尝试做一些不同的事情,所以我提交了一个新的更改,它将使用不同的提交消息创建一个不同的条目(比如说我添加了一个我想要实验的新函数。

现在问题是:如果我想回到我以前的工作,在创建这个新补丁之前,我该怎么做?

如果我提交新的更改,即使使用--amend,它们也会使用最新的补丁,而不是之前的补丁。我是否必须在之前的提交中进行硬重置?如果我这样做,我是否会松开其他补丁中的代码更改?

总结:

make changes-->commit to A with --amend (the changes go on the same patch
changes with new function--> commit B (new commit message)
changes--> commit A --amend (changes goes to B now)

现在更改将进入提交B,即使使用--amend而不是提交A

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作:

git stash # Put all the changes aside for a moment
git rebase --interactive COMMIT # Switch to the commit you want to amend
git stash pop # Pull all the changes back so the commit can be amended
git commit --amend # Amend it
git rebase --continue # Rebase everything commited after the amended commit
                      # so that it looks like the changes were always there

但是请注意,除了更改修改提交的哈希之外,这也会更改所有重新提交的提交的哈希值,因此当提交已经被推送到上游时,应该避免这种情况。在这种情况下,你没有太多选择,只能进行新的提交。

相关问题