当git rm和git在不同文件上添加时,文件已重命名 [英] File renamed when git rm and git add done on different files

查看:109
本文介绍了当git rm和git在不同文件上添加时,文件已重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just did git rm file1.c after which git status shows

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我明白了

All well and good so far. But then if I git add dir/file2.c I get

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绝没有相似的内容[edit].

Is this a bug or am I doing it wrong? I would expect the new file to be listed as new file. file1.c and file2.c does in no way have similar content [edit] besides for a short copyright notice [\edit].

推荐答案

这不是bug,这是一个功能.

This is not a bug, this is a feature.

当您删除文件,然后在大多数代码相同的情况下添加另一个文件时,此操作等效于重命名该文件.

When you remove a file, and then add another file where most of the code is same, it is an operation which is equivalent to renaming the file.

因此,git将其显示为

Hence, git displays it as

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

检查有关更多详细信息,请访问git-scm 上的此链接.另外,您可以检查 git无法检测到重命名

Check this link on git-scm for more details. Also, you can check git fails to detect renaming and How does git detect similar files, for its rename detection.

这篇关于当git rm和git在不同文件上添加时,文件已重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆