1

我以前一直在开发一个 SDK,现在我收到了一个新的代码。

在开始这个项目时,我创建了一个导入分支,我在该分支上提交了 SDK,并将其合并到我的主分支作为第一次提交。

但是现在有了这个新版本的 SDK,我注意到目录结构发生了很大变化。相当多的文件已被移动到子目录中,以改善我猜的代码库的结构。

所以我想在导入分支上有一个新的提交,所以将它合并到主分支会更容易,但我不知道如何指示 git 文件已被移动。

git mv file_a dir_a/file_a

...不起作用,因为目标文件存在。所以我尝试了:

git mv -f file_a dir_a/file_a

也不是我想要的,因为目标位置被旧版本的内容覆盖。

我还尝试首先将所有内容 gitmoving 以类似于新的目录结构,然后将所有内容复制过来。但 git 仍将其视为删除旧文件并添加新文件。

那么在这里进行的方法是什么?欢迎任何提示/指针!

4

1 回答 1

1

git不跟踪移动,因此您不能直接执行此操作。 git尝试通过查看添加的文件是否与已删除的文件很相似来动态识别移动的文件。所以只是git rm旧文件和git add新文件,看看git status说了什么。您可以在 中修改重命名检测的行为git log,这里是相关部分的副本git help log

-M[<n>], --find-renames[=<n>]
   If generating diffs, detect and report renames for each commit. For following
   files across renames while traversing history, see --follow. If n is
   specified, it is a threshold on the similarity index (i.e. amount of
   addition/deletions compared to the file’s size). For example, -M90% means git
   should consider a delete/add pair to be a rename if more than 90% of the file
   hasn’t changed. Without a % sign, the number is to be read as a fraction, with
   a decimal point before it. I.e., -M5 becomes 0.5, and is thus the same as
   -M50%. Similarly, -M05 is the same as -M5%. To limit detection to exact
   renames, use -M100%.
于 2013-07-17T12:18:49.267 回答