2017-09-26 53 views
0

我在GitHub(企业版)上做了一个PR,提交的次数很少。我的评审鉴定的一个小错误犯:有什么解决方案来修改合并请求?

* a401341c Did this (HEAD -> foo) 
* 08e97f86 Did that 
* 616cd4ad Done that 
* f3c6151b Accomplished this 
* 1af6e74f Fix this <-- Error there 
* a099fc19 Finished this 
* ab726eb3 Cherry-picked this (master, origin/master) 

第一个解决方案是1af6e74f后恢复所有提交,因为我不能只是恢复它没有冲突,然后重新所有提交与修正:

* 0c99cf29 Reapply Did this (HEAD -> foo) 
* 8806f36b Reapply Did that 
* 572e1122 Reapply Done that 
* 64ea3dc8 Reapply Accomplished this 
* 81e20976 Fix this (this time correctly) 
* d78a4534 Revert Fix this <-- Error there 
* c0d817a9 Revert Accomplished this 
* ed2bb3b2 Revert Done that 
* ea34322a Revert Did that 
* f81b78a3 Revert Did this 
* a401341c Did this 
* 08e97f86 Did that 
* 616cd4ad Done that 
* f3c6151b Accomplished this 
* 1af6e74f Fix this <-- Error there 
* a099fc19 Finished this 
* ab726eb3 Cherry-picked this (master, origin/master) 

然后git push更新我的PR。

第二个解决方案将涉及git push -f

git checkout 1af6e74f 
git commit --amend -am "Fix this (with corrections)" 
git rebase --onto a401341c f3c6151b HEAD # Not sure this will work as written 
git branch -f foo HEAD 
git push -f 

是前者的解决方案很好的解决,总是后者坏事呢?

+1

我也不会要么使用,我只想解决布布在一个新的承诺。当然,如果你重新启动分支,历史将会更加清晰。但是,如果您的分支不被其他人共享,重新分配只是明智之举。所以你的问题的答案是,如果分支不共享,后一种解决方案是一个很好的解决方案。 –

+0

嗯,我不能......在我的问题中,我没有说清楚,因为我使用'git mypatch',我不能只应用一个补丁。我需要恢复和更改特定的提交。这就像我在一次提交中做了'/ a \ w/b/g',之后我不能真正执行's/b/a/g'。 – nowox

+0

如果你不能兑换,那你为什么要问这个问题,还是这个问题只是假设? –

回答

1

问题

什么是你的老枝和新的分支(git的差异a401341c 0c99cf29)之间的差异?
它看起来像一个合理的补丁,它足够清楚地表明错误是如何修复的?


如果是这样,只是采取新的内容,并承诺以此为新的提交你的老枝之上:

git checkout foo 

# just to be on the safe side : work on a new temporary branch 
git checkout -b wip 

# go back to the old sate : 
git reset --hard a401341c # <- original "Did this" commit 

# get the content from new branch : 
git checkout 0c99cf29 . # <- don't forget the "." 

# check that it matches what you expect : 
git diff [--cached] ... 
git difftool -d [--cached] ... 

# if OK : commit ! 
git commit 


# make your local "foo" branch point to this commit : 
git checkout foo 
git reset --hard wip 
git branch -d wip 

# push : 
git push origin foo 
+0

在这种情况下,我必须执行通常不被允许的'git push -f origin foo'。对 ? – nowox

+0

这将是regumar的推动,而不是'git push -f'。您的更改将在远程分支之上提交。 – LeGEC