我处于这样一种情况,即功能分支中的某些更改不会反映在master中,即使此分支已合并到其中.我无法理解为什么.为简单起见,假设此提交具有哈希"A"并更改了文件"文件"
这可以通过以下命令最好地说明:
$ git checkout master
$ git branch --contains A
* master
feature_branch
$ git log file | grep A
(no output)
$ git checkout feature_branch
$ git log file | grep A
A
Run Code Online (Sandbox Code Playgroud)
谁能解释一下这里发生了什么?更重要的是,有什么办法可以防止将来出现这种情况吗?
编辑:
正如一些人所提到的,以下确实显示了提交:
$ git checkout master
$ git log --follow file | grep A
A
Run Code Online (Sandbox Code Playgroud)
但事情是......文件没有重命名.所以这并没有完全解释事情,要么......
你是邪恶合并的受害者.
以下是如何重现它
git init testrepo
cd testrepo
touch initial
git add initial
git commit -m 'initial commit'
git checkout -b feature_branch
echo "A" >> file
git add file
git commit -m 'file committed'
git checkout master
Run Code Online (Sandbox Code Playgroud)
现在进行交互式合并,就好像存在合并冲突一样
git merge --no-commit --no-ff feature_branch
Run Code Online (Sandbox Code Playgroud)
并移动文件file
(邪恶合并).
testrepo (master|MERGING)
git mv file someOtherFile
git commit
Run Code Online (Sandbox Code Playgroud)
现在您将看到分支主机包含9469682
引入文件的提交(在我的情况下)file
git branch --contains 9469682
feature_branch
* master
Run Code Online (Sandbox Code Playgroud)
但git日志不会显示它,因为它被移动了
git log -- file
(no output)
Run Code Online (Sandbox Code Playgroud)
使用
git log --follow -- file
Run Code Online (Sandbox Code Playgroud)
并再次出现提交.
还要记住合并可能会变得更加邪恶.如果file
内容也发生了很大变化git log --follow
,那么由于重命名阈值,èven 将无法检测到它.
在这种情况下,用于git log --follow --find-renames=
调整重命名阈值.
如果生成差异,则检测并报告每次提交的重命名.要在遍历历史记录时通过重命名跟踪文件,请参阅--follow.如果指定了n,则它是相似性指数的阈值(即与文件大小相比的添加/删除量).例如,-M90%表示如果超过90%的文件未更改,Git应将删除/添加对视为重命名.如果没有%符号,则该数字将作为分数读取,并在其前面加上小数点.即,-M5变为0.5,因此与-M50%相同.同样,-M05与-M5%相同.要将检测限制为精确重命名,请使用-M100%.默认相似性指数为50%.
如果文件的位置以某种方式发生了变化,您可能需要git log
告诉follow
:
$ git checkout master
$ git log --follow -- file | grep A
Run Code Online (Sandbox Code Playgroud)
git log --oneline -- file
您可以检查和之间是否存在差异git log --oneline --follow -- file
,以查看文件是否已被重新定位。