我是一个新加入团队的程序员。在我的第一天,我在一个阶段中看到了这个被重命名的文件,准备通过git提交:
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: .gitignore
new file: reports/SQLS.rar
renamed: account/enter_rules.php -> enter_rules.old.php
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: account/enter_rules.old.php
Untracked files:
(use "git add <file>..." to include in what will be committed)
account/enter_rules.php
对于前两行,我没有问题。我知道正在发生什么。但是对于最后一行重命名:,我不确定应该做什么。系统运行良好。
在工作目录中,我有:
account/enter_rules.php
我找不到enter_rules.old.php文件。
似乎其他程序员从该文件创建了一个副本,将实际文件命名为.old,并进行了一些测试和新代码,然后暂存了更改并忘记提交。然后他手动删除了old.php。
在处理这种情况时,应采取什么最好的方法?我想在开始工作并进行自己的更改之前清除git状态。
我发现了这篇文章,但我不确定在我的情况下是否应该或能够提交。处理git中的文件重命名
阅读了所有建议后,对我帮助很大。这是我所做的:
- 我只是为了安全起见从文件
enter_rules.php
中复制了一份。 - 我“告诉”git(INDEX)文件名已更改。
$ git commit -m“提交名称更改”
。此时,git不知道.old已被删除。 - 然后我键入
$ git rm“account / enter_rules.old.php”
以解决行:Changes not staged for commit:。与使用$ git add。
相同的方式“告诉”git跟踪<file>
,我们应该使用$ git rm <file>
“告诉”git忘记这个<file>
。 - 然后我键入
$ git status
,我收到绿色消息:deleted: account/enter_rules.old.php。所以我应该告诉索引,.old文件已被删除。我键入$ git commit -m“提交删除更改”
- 现在git知道enter_rules.php已重命名为enter_rules.old.php,然后删除了enter_rules.old.php。
- 然后我解决了最后一行(Untracked files:)。我告诉git创建了一个新文件,并将其命名为enter_rules.php。我添加并提交了它。
所有的建议都帮助我解决了问题,所以我会尽量公正,将支票给予那些点数较少的人。
git status
显示的内容,看起来你的同事运行了git mv enter_rules.php enter_rules.old.php
然后将该文件复制回 enter_rules.php?他为什么要这样做呢? - Byte Labenter_rules.old.php
,但你确实需要account/enter_rules.php
,对吗? - Byte Lab