我有两个本地git存储库,它们都指向同一个远程存储库。

在一个git存储库中,如果我使用了git format-patch 1,我如何将该补丁应用到另一个存储库?


当前回答

git apply name-of-file.patch

其他回答

git apply name-of-file.patch

或者,如果你想用老办法:

cd /path/to/other/repository
patch -p1 < 0001-whatever.patch

如果你使用的是JetBrains IDE(如IntelliJ IDEA, Android Studio, PyCharm),你可以拖动补丁文件并将其放入IDE中,然后会出现一个对话框,显示补丁的内容。你现在所要做的就是点击“应用补丁”,一个提交将被创建。

另一种方法是将一个本地存储库作为远程存储库添加到另一个本地存储库。

$ cd repo1
$ git remote add repo2 file:///path/to/repo2/.git

这样你就可以获取分支,重构本地分支,或者从一个本地回购选择提交到另一个。

$ git remote update repo2
$ git fetch repo2 branch:branch-from-repo2
$ git log branch-from-repo2

首先,你应该注意git am和git apply之间的区别

当你使用git am时,你通常想要应用很多补丁。因此应该使用:

git am *.patch

或者是:

git am

Git会自动找到补丁并按顺序应用它们;-)

乌利希期刊指南 在这里您可以找到如何生成这样的补丁