git - 为什么 cherry-pick 告诉我所有线路都已更改?

标签 git diff git-cherry-pick

已更新

考虑文件 abc,在提交 A 和 B 中相同

begin
 123
 456
 789
 klm
end

在 A 中,我们重构第一行 123 => AAA 并在结果之上选择 B。 Git 告诉 文件中的所有行都已更改。但是,如果我们通过更新任何一行来修改 B,它的 diff 将正常运行。 Git 会注意到在这种情况下只有这一行文本发生了变化,如果它也是第一行则报告单行冲突。

这里是重现的代码

mkdir full-shit ; cd full-shit
git init ; echo rrr > root ; git add root
git commit -m root

git checkout -b A ; git checkout -b B

function makeABC {
    echo begin > abc
    echo " 123" >> abc
    echo " 456" >> abc
    echo " 789" >> abc
    echo " klm" >> abc
    echo end >> abc
}

echo commiting ABC into branch B
makeABC ; git add abc ; git commit -m abc

echo will make a new file for A instead of 'git cherry-pick B'
git checkout A ; makeABC
echo 'git checkout A ; git cherry-pick B' would work equally well to make copy A = B
sed -i -e 's/123/AAA/g' abc
git add abc ; git commit -m "A refactored"


echo observe that !!!PICKING B TELLS THAT ALL LINES BETWEEN A AND B ARE DIFFERENT!!!
echo whereas if we picked C instead of B this would not happen -- git would make the diff operation properly, detectinc collision at the frist line of abc
case "B" in
    "B") git cherry-pick B ;;
    "B2") git checkout B
        sed -i -e 's/123/BBB/g' abc
        git add abc ; git commit -m BBB
        git checkout A ; git cherry-pick B ;;
esac

git gui & 

echo 'full-shit' folder created

请注意 Git Gui 将所有行标记为冲突,而 EOL 字符在两次提交中完全匹配,因为它们是在同一运行中通过相同代码创建的,您甚至可以使用从 B 到 A 的 cherry-pick 来避免文件系统精确复制的操作。

出于这个原因,我认为这个问题与 previous one 相关,而不是与 EOL 相关,后者通常会导致类似的结果。同样在那种情况下,如果我在 B 中的第一次提交之上添加 B2 更改,git 开始区分单行。git 的逻辑是什么?

最佳答案

如果您更改换行符类型(Windows 换行符与 Unix 换行符),有时会发生这种情况。 git 可以显示忽略空白更改的差异。

关于git - 为什么 cherry-pick 告诉我所有线路都已更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34189779/

相关文章:

git - 如何使用 git cherry-pick 跳过不精确的重命名检测

mysql - 比较两个 MySQL 数据库

Git - 旧提交中分支之间的差异

git - 谁能解释一下 git cherry-pick <sha> 的作用?

java - 如何在 Eclipse 中将 github maven 项目作为 jar 文件导入?

algorithm - 网页更新检测算法

gerrit - 错误 : addinfo_cache failed while cherrypicking

git - 子目录到独立存储库中,然后 merge 回主存储库

git - 我可以从 .git/info/exclude 覆盖 .gitignore 中的任何忽略规则吗

git - 将 10000 个小文本文件放入代码库,会使 git 变慢吗?