如何使 git 将删除的文件和新文件标记为文件移动? [英] How to make git mark a deleted and a new file as a file move?

查看:17
本文介绍了如何使 git 将删除的文件和新文件标记为文件移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我手动移动了一个文件,然后我修改了它.根据 Git,它是一个新文件和一个已删除的文件.有没有办法强制 Git 将其视为文件移动?

I've moved a file manually and then I've modified it. According to Git, it is a new file and a removed file. Is there any way to force Git into treating it as a file move?

推荐答案

如果您的修改不是太严重,Git 会自动检测移动/重命名.只需 git add 新文件,git rm 旧文件.git status 然后将显示它是否检测到重命名.

Git will automatically detect the move/rename if your modification is not too severe. Just git add the new file, and git rm the old file. git status will then show whether it has detected the rename.

此外,要在目录中移动,您可能需要:

additionally, for moves around directories, you may need to:

  1. cd 到该目录结构的顶部.
  2. 运行 git add -A
  3. 运行 git status 以验证新文件"现在是重命名"文件
  1. cd to the top of that directory structure.
  2. Run git add -A .
  3. Run git status to verify that the "new file" is now a "renamed" file

如果 git status 仍然显示新文件"而不是重命名",您需要遵循 Hank Gay 的建议在两个单独的提交中移动和修改.

If git status still shows "new file" and not "renamed" you need to follow Hank Gay’s advice and do the move and modify in two separate commits.

这篇关于如何使 git 将删除的文件和新文件标记为文件移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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