我刚刚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
这是一个错误还是我做错了?我希望新文件列为新文件。除了简短的版权声明[\ edit]之外,file1.c和file2.c绝不会有类似的内容[编辑]。
答案 0 :(得分:7)
这不是错误,这是一个功能。
删除文件,然后添加大多数代码相同的另一个文件时,这是一个等同于重命名文件的操作。
因此,git将其显示为
renamed: file1.c -> dir/file2.c
查看this link on git-scm了解详情。此外,您还可以查看git fails to detect renaming和How does git detect similar files, for its rename detection。