【问题标题】:git incorrectly tags a file as rename [duplicate]git错误地将文件标记为重命名[重复]
【发布时间】:2014-12-07 04:03:13
【问题描述】:

我有两个文件已经在 git 中添加并提交。

报告
报告日期

现在,我修改了这两个文件并尝试提交,但在我将它们添加到暂存区域后,git 错误地将 report_dates 文件标记为重命名。

> git status
On branch master
Changes not staged for commit:  
  (use "git add <file>..." to update what will be committed)  
  (use "git checkout -- <file>..." to discard changes in working directory)  
      modified:   report
      modified:   report_dates

> git add report
> git add report_dates

> git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
      renamed:    report_dates -> report
      modified:   report_dates

我尝试使用 git commit --dry-run 进行验证,这也显示文件已重命名。提交会覆盖原始文件吗?有两个不同的文件,90% 的内容相似。

【问题讨论】:

  • 这就是 git 的工作方式。如果文件内容更改太多,有时它不会检测到实际的重命名。你应该接受它并继续前进:)
  • stackoverflow.com/q/26273245/6309 中的相同: git status after 提交将起作用。
  • 感谢@VonC git commit --dry-run 将其显示为重命名。我还能继续承诺吗? @AlexMDC 这不是重命名,但 git 将其报告为重命名。
  • 当然:如果不成功,您仍然可以重置为上一次提交。
  • 提交后正确显示

标签: git


【解决方案1】:

正如我之前在“git status shows rename but it's incorrect”中解释的那样,您需要实际提交才能看到正确的状态。

git status之前提交:

  • 仍然基于索引,看起来已经进行了重命名。
    有时git commit --dry-run -a(注意-a)可以提供帮助。
  • 检测到:
    • report_datesbeing moved(重命名为report
    • report_dates正在修改中

它(git status)在您实际提交之前不会确定:您可能仍会在提交之前删除report_dates

但实际提交将注册这两个文件(没有覆盖),并且新的 git status 不会显示任何重命名(如 OP shnazzconfirmed)。

【讨论】:

    猜你喜欢
    • 2020-05-30
    • 1970-01-01
    • 2015-07-16
    • 2011-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-07
    • 2016-04-15
    相关资源
    最近更新 更多