如何将git标记删除并将新文件作为文件移动? [英] How to make git mark a deleted and a new file as a file move?
问题描述
我手动移动了一个文件,然后修改了它。根据Git,这是一个新文件和一个被删除的文件。有没有办法强制Git将它视为文件移动?
解决方案
Git会自动检测移动/重命名,如果你的修改不是太严厉。只需 git add
新文件,以及 git rm
旧文件。然后 git status
会显示它是否检测到重命名。
此外,对于目录中的移动,您可能需要: 到该目录结构的顶部。
git add -A。
git status
来验证新文件现在是重命名文件
如果git状态仍显示新文件而不是重命名,则需要遵循 Hank Gay 的建议,并执行移动并修改两个单独的提交。
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 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:
- cd to the top of that directory structure.
- Run
git add -A .
- Run
git status
to verify that the "new file" is now a "renamed" file
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屋!