处理不同的 git 个补丁?
Handle different git patches?
示例:我有一个我提交的回购协议;我有我的分支机构,我在做一个功能。
我使用 --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
您可以执行以下操作:
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
但是请注意,除了更改修改后的提交的哈希值之外,这还会更改所有重新设置的提交的哈希值,因此当提交已经被推送到上游时应该避免这种情况。在这种情况下,您别无选择,只能重新提交。
示例:我有一个我提交的回购协议;我有我的分支机构,我在做一个功能。 我使用 --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
您可以执行以下操作:
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
但是请注意,除了更改修改后的提交的哈希值之外,这还会更改所有重新设置的提交的哈希值,因此当提交已经被推送到上游时应该避免这种情况。在这种情况下,您别无选择,只能重新提交。