我是团队中的新程序员.在我的第一天,我将这个重命名的文件放在一个舞台上,准备由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
Run Code Online (Sandbox Code Playgroud)
对于前2行,我没有问题.我知道发生了什么事.但是对于最后一个改名为:,我不确定应该做些什么.该系统运作良好.
在工作目录中我有:
account/enter_rules.php
Run Code Online (Sandbox Code Playgroud)
我找不到enter_rules.old.php文件.
看起来其他程序员已经从文件中创建了一个副本,命名为.old,实际上是一些测试和新代码,而不是分阶段进行更改而忘记提交.比他手动删除了old.php
应对这种情况的最佳方法是什么?我想在开始处理它并进行自己的更改之前先把git状态清楚.
我找到了这篇文章,但我不确定我是否应该或可以在我的情况下做出承诺.在git中处理文件重命名
在阅读了所有建议后,这对我有很大帮助,这就是我所做的:
enter_rules.php $git commit -m "committing name changes".此时git不知道.old被删除了.$git rm "account/enter_rules.old.php"来解决这个问题:没有为commit提交的更改:.以同样的方式我们用$git add ."告诉"git来跟踪a <file>,我们应该用$git rm <file>"告诉"git来忘记这一点<file>.$git status,我收到了绿色信息:已删除:account/enter_rules.old.php.所以我应该告诉索引,.old文件已被删除.我打字了$git commit -m "committing delete changes"所有的建议都帮助我解决了这个问题,所以我会尽量公平,并且会给那些不那么重要的支票.
我似乎很清楚这里发生了什么:
在初始状态下有两个文件account/enter_rules.php和account/enter_rules.old.php。
你的同事一定做过这样的事:
git rm account/enter_rules.old.php
git mv account/enter_rules.php account/enter_rule.old.php
Run Code Online (Sandbox Code Playgroud)
然后编辑一个新的account/enter_rules.php并将其保留下来。
如果您对这些更改感到满意
git add account/enter_rules.php
git commit
Run Code Online (Sandbox Code Playgroud)
别的
rm account/enter_rules.php
git reset HEAD
Run Code Online (Sandbox Code Playgroud)
撤消他的更改。
对我来说,听起来很奇怪的是,为什么您要在同事克隆的存储库上进行未提交的更改?
| 归档时间: |
|
| 查看次数: |
406 次 |
| 最近记录: |