git status显示重命名,但不正确

时间:2014-10-09 08:01:15

标签: git rename

我使用Rails开发。我有一个名为cpc_admin_controller.rb的控制器,完整路径为app/controllers/cpc_admin_controller.rb,完整路径为admin_helper.rb的帮助器为app/helpers/admin_helper.rb。然后我从admin_helper.rb删除一个方法到cpc_admin_controller.rb,并保存,使用git提交。

但是git显示如下消息

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   renamed:    app/helpers/admin_helper.rb ->    app/controllers/cpc_admin_controller.rb
#   modified:   app/helpers/admin_helper.rb

我认为它应该显示两个像这样的修改,而不是重命名的

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   app/controllers/cpc_admin_controller.rb
#   modified:   app/helpers/admin_helper.rb

有人可以帮助我,告诉我为什么?

1 个答案:

答案 0 :(得分:6)

this thread

所示
  

Git不关心单个文件或重命名,它跟踪整个树木   它显示为重命名只是基于两个文件内容的最佳猜测。

Git状态确实perform rename detection using a heuristic 但是一旦你提交,你会发现这两个文件是分开的。