有没有一种方法来识别特定提交的“附带”提交(正在编辑相同行并将导致冲突的提交)?
一个非常简单的例子
$ git init
$ echo test > test
$ git add test
$ git commit -m "First commit"
$ echo test1 > test
$ git commit -am "Second commit"
$ git l
* 95a29dd Second commit
* 30a68e6 First commit
$ type test
test1假设在这一点上,无论出于什么原因,我都想还原30a68e6。
$ git revert 30a68e6
error: could not revert 30a68e6... First commit
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'当然,这会导致冲突,因为95a29dd编辑了相同的行。
有没有可能提前发现恢复30a68e6会导致冲突,如果是的话,用什么提交(即95a29dd)?
为了给出一点上下文,我需要这个,因为我需要一些提交被自动恢复。在这种情况下,如果我知道30a68e6应该被还原,我希望能够识别“抵押品”提交,它应该首先被还原以避免任何冲突(如30a68e6)。我知道只要恢复所有的30a68e6..HEAD就行了,但我希望避免恢复不会与30a68e6冲突的提交。
发布于 2016-01-10 15:02:09
(免责声明:此答案与我对Is there some kind of 'git rebase --dry-run', which would notify me of conflicts in advance?的答案类似。)
是否有可能提前发现恢复
30a68e6会导致冲突,如果是,使用什么提交(即95a29dd)?
在撰写本文时(Gitv2.7.0),在实际尝试恢复之前,Git没有提供任何方法来确定您是否会遇到冲突。
但是,如果您运行git revert并遇到冲突,该进程将停止并以非零状态退出。您可以做的是检查还原操作的退出状态,如果不是零,则运行git revert --abort取消还原:
git revert ... || git revert --abort
发布于 2016-01-09 05:33:11
git revert应该很容易撤消。检查恢复的返回代码,如果失败(返回代码1),则运行git revert --abort;如果成功(返回代码0),则运行git reset --hard HEAD~1,并且您不想保留它。
根据您的需要,您可以将其与git bisect结合使用来搜索历史记录。
https://stackoverflow.com/questions/34685387
复制相似问题