我有一个名为 master
的分支和一个名为 feature
的分支。一周前我 merge 了feature
进入master
但后来意识到该功能还没有真正准备好,所以我 revert
编辑了 merge 。
现在我准备 merge feature
进入master
再次,但只 merge 了一些文件 - 因为 Git 正在查看历史记录并认为 master revert
应该优先,并且不包含 feature
中存在的一堆文件。我真的想要。
我想要的是一种交互方式查看两个分支之间的差异并选择我想要保留的文件、处理任何 merge 冲突等的方法。但是 git merge
拒绝承认这两个分支之间有任何差异。
我怎样才能做到这一点?
最佳答案
我发现这很有趣Git revert
这个问题的美妙之处在于,git revert
的最佳功能就是创建问题。使用 git revert from git reset 的最大优点是
It doesn’t change the project history, which makes it a “safe” operation for commits that have already been published to a shared repository. For details about why altering shared history is dangerous, please see the git reset page.
git revert
本身就是一次提交。你应该使用 git reset --hard ,我猜你有使用 git revert 的原因。
It's important to understand that git revert undoes a single commit—it does not “revert” back to the previous state of a project by removing all subsequent commits.
在推送提交之前撤消 merge 。
git revert -m 1 <commit>
但请记住,这里真正的问题是,您必须先恢复恢复,然后才能再次提交分支,或者再次重新 merge 它。
无论如何,我在这个星球上找到了一个很棒的人,他详细地解释了完全相同的问题。是的,完全相同的问题。我很高兴在这里介绍他:
Linux Torvalds explaining the git-revert conflict
I have a master branch. We have a branch off of that that some developers are doing work on. They claim it is ready. We merge it into the master branch. It breaks something so we revert the merge. They make changes to the code. they get it to a point where they say it is ok and we merge again.
When examined, we find that code changes made before the revert are not in the master branch, but code changes after are in the master branch.
这也可能对您有帮助:
关于git - 两个分支的力比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32702152/