gpt4 book ai didi

git - 当 git rm 和 git add 在不同文件上完成时文件重命名

转载 作者:太空狗 更新时间:2023-10-29 14:28:12 27 4
gpt4 key购买 nike

我刚刚做了 git rm file1.c 之后 git status 显示了

On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

deleted: file1.c

Untracked files:
(use "git add <file>..." to include in what will be committed)

dir/file2.c
dir/file3.c

到目前为止一切都很好。但是如果我 git add dir/file2.c 我得到

On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

renamed: file1.c -> dir/file2.c

Untracked files:
(use "git add <file>..." to include in what will be committed)

dir/file3.c

这是一个错误还是我做错了?我希望新文件被列为新文件。 file1.c 和 file2.c 除了简短的版权声明 [\edit] 外,绝对没有相似的内容 [edit]。

最佳答案

这不是错误,这是一个特性。

当你删除一个文件,然后添加另一个大部分代码相同的文件时,这是一个相当于重命名文件的操作。

因此,git 将其显示为

renamed:    file1.c -> dir/file2.c

检查 this link on git-scm更多细节。另外,您可以检查 git fails to detect renamingHow does git detect similar files, for its rename detection .

关于git - 当 git rm 和 git add 在不同文件上完成时文件重命名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27018930/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com