首页 > 解决方案 > Git比较目标分支中的missies文件,将源分支的所有代码作为新代码

问题描述

代码更改后,我正在尝试从 GIT 网页创建代码审查。源分支是我的开发分支,目标分支是我的主分支。但是差异似乎忽略了 master 分支的所有代码,将 dev 分支的每一行都视为新的。

在 git 网页比较中再次尝试了这个,同样的问题。

我尝试git diff master..dev file1.py使用本地笔记本电脑命令,这可以正确显示我的更改。

经过一番搜索,似乎在 GIT Web 视图中,它正在将 diff 与最新的共同祖先进行比较,而不是与 master 和 dev 中的最新代码进行比较。GIT rebase 似乎正在解决这个问题。但是有没有其他方法可以处理这个问题?谢谢!

标签: gitcomparediff

解决方案


You haven't said what web interface you're using, but I'm going to presume it's GitHub for now. On GitHub, the default comparison does a diff with the three-dot operator ..., not the two-dot operator ...

When you do a comparison with git diff master..dev (two dots), it shows the differences between master and dev. When you do a comparison with git diff master...dev (three dots), it takes the symmetric differences, which is the range of commits reachable from either side but not both. That's why it looks like you're comparing against the latest common ancestor: because that's the merge base and you are. If you want to do two-dot comparison, you can edit the URL.

If you're interested in learning more, you can see the gitrevisions(7) manual page, and GitHub also has documentation.


推荐阅读