git - 两个分支的力比较

标签 git merge

我有一个名为 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.

这也可能对您有帮助:

Re-doing a reverted merge in Git

关于git - 两个分支的力比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32702152/

相关文章:

mysql - 将两个mysql表合并成第三个表

r - 如何合并 2 个数据框?

version-control - bzr merge - 在提交之前审查另一个分支提交说明 ('merge tips' )

git commit 打破时区

git - git pull 是否以原子方式写入文件

git - 解析heroku.yml时出现问题-build.web是一个禁止的属性

git - git 分支重命名会影响分支层次结构吗?

lambda - 合并两个 Map<String, Set<String>> 类型的 Map

Git:在恢复之前分支后 merge 更改

git - 撤消 git 快进 merge