Git 查找重命名并自动保留历史记录

问题描述 投票:0回答:1

我有一个提交 A,其中包含 1000 项修改/创建/删除。 基本上 90% 的创建/删除都是移动。 我跑步时确实可以看到它

git status --find-renames

问题是我的 PR 在 Azure DevOps git 及其历史记录中看起来像垃圾。

我考虑过将其分成两个提交(仅移动/创建/删除和仅更改),但不知道如何自动执行。

如何解决?

git azure-devops
1个回答
0
投票

我考虑过将其分成两个提交(仅移动/创建/删除和仅更改),但不知道如何自动执行。

自动化将提交拆分为移动/创建/删除和更改的过程可能有点棘手,因为 Git 没有提供内置的方法来执行此操作。

我们先手动使用 Git 命令来完成此过程。

例如,如果你的文件移动涉及的路径较少,而文件修改涉及的路径较多,则可以使用以下git命令

git add "path to moved file"
git commit -m "File moves"

git add -A  # or git add “path to modified file”
git commit -m "File modifications"

git push

如果您的文件移动涉及很多路径而文件修改涉及较少 路径,您可以使用以下 git 命令

git add “path to modified file” 
git commit -m "File modifications"

git add -A   # or git add "path to moved file" 
git commit -m "File moves"

git push

然后,您可以创建一个使用 Git 命令的脚本来自动执行此过程。当然,您需要将路径传递给脚本。

© www.soinside.com 2019 - 2024. All rights reserved.