Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge single file from another repository into my own

Say I have my own git repo with a bunch of text files in it. There is another different git repo that someone else owns with a bunch of text files that all differ from my own except for one file.

I am continuously making changes to the different text files in my repo, but every now and then I want to merge any changes of that single file from the other repo into my own.

Is there any easy way of going about doing this? I've searched around and found some similar questions but none that we're for my exact scenario.

like image 948
btse Avatar asked Apr 26 '14 18:04

btse


People also ask

Can I git merge a single file?

In Conclusion. We can use git checkout for far more than simply changing branches. If we supply it with a branch name and a file, we can replace a corrupted or broken file. Instead, if we want to pass some of the changed content we can use the --patch flag to manually merge an individual file.

How do I add files from one git repo to another?

Merge the files into the new repository B. Step 2: Go to that directory. Step 3: Create a remote connection to repository A as a branch in repository B. Step 4: Pull files and history from this branch (containing only the directory you want to move) into repository B.


1 Answers

You can merge arbitrary files or repo objects. Simplest might be:

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`
like image 57
jthill Avatar answered Oct 29 '22 04:10

jthill