git - 如何在具有更改历史记录的存储库上应用 git 补丁?

标签 git git-patch

最近我从 SVN 迁移到 git,我的团队已经开始在新的 git 存储库中工作。

后来我发现了一些转换问题,并从 SVN 制作了第二个 git repo,并进行了一些修复和历史重写。

现在我有了 SVN 存储库的第二个 git 副本(我对此感到满意),我想用我的团队在第一个 git 存储库中所做的更改来修补它。

为此,我尝试使用 git 补丁:

  • git-format-patch --zero-commit --stdout > master.patch 创建 已经对第一个 git 的 master 进行更改的单个文件 repo
  • git-am 将来自 *.patch 文件的提交应用到 master 第二个存储库的

我指定了--zero-commit,因为补丁文件中的哈希值是错误的,所以我实际上有两个不同的存储库。

问题是,当我尝试使用 git am master.patch 应用补丁时,我得到:

Applying: %commit_name% error: patch failed: readme.md:5 error: readme.md: patch does not apply Patch failed at 0001 %commit_name% The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".

即使我在这个补丁中只有一个提交,我想将它应用到同一个 repo 上以获得相同的提交,但在另一个分支上。

最佳答案

看起来像添加 --ignore-whitespacegit am 解决了主要问题,但我仍然有这样的警告:

.git/rebase-apply/patch:56: trailing

warning: squelched 9 whitespace

errors warning: 14 lines add whitespace errors.

关于git - 如何在具有更改历史记录的存储库上应用 git 补丁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40864182/

相关文章:

git - 用于生产和暂存/开发的不同 composer.json 文件

git - 你能在 git commit 期间更改文件内容吗?

git - 在本地从 Detached HEAD 进行一系列提交后,如何更新远程分支?

git - 如何将 git 补丁从一个存储库应用到另一个存储库?

c# - 如何获取包含 libgit2sharp 中提交的远程分支列表

git - 如何使用gitlab搜索条件

当你不能推或 pull 时的 Git 工作流

git - 是否可以从一个目录创建 git 补丁并将该补丁应用到不同的目录?

git pull 远程主在分离的头部