复制文件的 Git diff
假设我有一个文件 myfile.txt。其中有一段文本,我将其复制到一个新文件 myfile2.txt 中。
如果我 git diff,它会将 myfile2.txt 显示为新文件。好的。现在,我将每次出现的“the”替换为“hello”并提交。
我遇到的问题是,提交发生后, git diff 会将所有 myfile2.txt 显示为新文件,并且不会显示“the”已在各处被“hello”替换(因为就其而言)关心一切都是新的变化)。
即使我在编辑之前首先提交并推送 myfile2.txt 以使更改显而易见,但这也不是一个好的解决方案。这是一个问题,因为如果我将提交压缩到一个功能并提交它,myfile2.txt 将显示为一个全新的文件,而我希望看到这些替换已经完成。
git 是否有一个功能可以让我跟踪从另一个文件复制的文件中的更改,这样 git diff 只会向我显示这些修改,而不是整个添加的文件?
Say I have a file, myfile.txt. It has a paragraph of text in it, and I copy it to a new file, myfile2.txt.
If I git diff, it will show myfile2.txt as a new file. Okay. Now I replace every occurrence of "the" with "hello" and commit.
The problem I'm having is that after the commit happens, git diff will show all of myfile2.txt as a new file and it will not show me that "the" has been replaced by "hello" everywhere (because as far as it's concerned everything is a new change).
Even if I first commit and push myfile2.txt prior to editing so that the changes are evident, that's not a good solution. It is a problem because if I squash commits down to a feature and commit it, myfile2.txt shows up as a brand new file, whereas I would like to see that those replacements have been made.
Does git have a feature that allows me to track changes in a file that was copied from another, such that a git diff will show me only those modifications and not the added file as a whole?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
git diff -M
/git diff -C
try
git diff -M
/git diff -C
我最近有一个关于目录重命名问题的类似问题与类似的建议。
还有 --patience 选项可以查看 git-diff-patience。
I had a similar question recently about the issue of directory renames with similar advice.
There is also the --patience option to have a look at git-diff-patience.