如何做“hg mv - after”在混帐? [英] How to do "hg mv --after" in git?

查看:169
本文介绍了如何做“hg mv - after”在混帐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在git之外重新命名了一些文件,并对它们进行了大量修改。当我运行
git diff-index -M --name-status HEAD 我只看到4个文件被重命名/移动,而它应该更多。



我知道我可以使用 hg mv --after 来记录Mercurial中的移动后期事件。我无法在git中找到等价物。是否有? 不要担心。只需提交文件即可,因为这实际上是您唯一的选择。



以下是Git如何查看从X到Y的重命名。

 提交#1:
- 文件名为X,内容为Hello,world!
提交#2:
- 文件名为Y,内容为Hello,world!

请注意,Git实际上并不关心您是否重命名了该文件,或者是否创建了新文件相同的内容。对Git来说,完全没有任何区别。



Git不记录存储库中的移动,也没有每个文件的历史记录。 Git只会将历史记录为整个存储库快照的图形。正常地使用> git add git commit ,否则你在这里做的任何操作都不起作用。如果使用 git mv ,它与 git rm git add git status 或者 git log 。

code>,如果添加的文件与删除的文件相似,则会显示删除和添加。 Git不使用存储库中的任何额外信息。如果您足够更改移动的文件,它将显示为单独的添加和删除。 Git通过比较新文件的内容和被删除​​文件的内容来做到这一点。这发生在你提出差异时,在数据已被提交之后。



默认相似性阈值为50%。如果您希望在小于50%的文件之间看到重命名,请将较低的百分比传递给 git diff-index 。例如,为了跟踪重命名,即使文件的75%发生了变化,使用这个:

  git diff-index -M25%


I renamed some files outside of git and modified them heavily. When I am running git diff-index -M --name-status HEAD I see only 4 files as renamed/moved, whereas it should be more.

I know that I can record the move post factum in Mercurial using hg mv --after. I cannot find an equivalent in git. Is there?

解决方案

Summary: Don't worry about it. Just commit the file normally, because that's literally your only choice.

Here's how Git views a rename from X to Y.

Commit #1:
  - File named "X" with contents "Hello, world!"
Commit #2:
  - File named "Y" with contents "Hello, world!"

Notice that Git does not actually care if you renamed the file or if you created a new file with the same contents. To Git, there is no difference at all.

Git does not record moves in the repository, and there is no per-file history. Git only records history as a graph of snapshots of the entire repository. Simply use git add and git commit as normal, nothing else you do here will have any effect. If you use git mv it is just the same as git rm and git add.

When you use git status or git log, it will display a deletion and addition as a move if the added file is similar enough to the deleted file. Git does not use any extra information in the repository. If you change the moved file enough, it will show up as a separate addition and deletion instead. Git does this by comparing the contents of the new file to the contents of the deleted file. This happens when you ask for the diff, after the data is already committed.

The default similarity threshold is 50%. If you want to see renames between files that are less than 50% similar, pass a lower percentage to git diff-index. For example, to track renames even if 75% of the file changes, use this:

git diff-index -M25%

这篇关于如何做“hg mv - after”在混帐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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