Git将另一个存储库中的单个文件合并到我自己的文件

bts*_*tse 10 git version-control

说我有自己的git repo,里面有一堆文本文件.还有另一个不同的git repo,其他人拥有一堆文本文件,除了一个文件外,它们都与我自己不同.

我不断对我的仓库中的不同文本文件进行更改,但我偶尔会将该单个文件的任何更改从其他仓库合并到我自己的库中.

有没有简单的方法来做这件事?我四处搜索并发现了一些类似的问题,但没有一个我们是我的确切场景.

tma*_*wen 7

尝试添加other-repo然后带它的分支包括你的target-branch

~ $ git remote add other git@github.com:username/other-repo.git
~ $ git fetch other
Run Code Online (Sandbox Code Playgroud)

切换到要合并的分支target-file.ext:

~ $ git checkout your-branch
Run Code Online (Sandbox Code Playgroud)

将目标文件合并到您的文件中:

~ $ git checkout -p other/target-branch target-file.ext
Run Code Online (Sandbox Code Playgroud)


jth*_*ill 5

您可以合并任意文件或 repo 对象。最简单的可能是:

git merge-file file.txt <(git show last-merged-file.txt) /path/to/their/file.txt
# resolve any conflicts, then
git tag last-merged-file.txt `git hash-object-w file.txt`
Run Code Online (Sandbox Code Playgroud)