Home > Enterprise >  How can merge folder(only one,not all) from one repository to second?
How can merge folder(only one,not all) from one repository to second?

Time:04-12

I have two repositories.In A repository i added one folder from B repository.But now i have some changes in this folder in B repository.How i can added changes from B repo from only one folder? I did git fetch git://repository.url/repo.git master:folder_name but it's added all folders

CodePudding user response:

You've got two options:

A) Create a patch from repo_b and apply it to repo_a (easier).

B) Add repo_b as a remote of repo_a and merge unrelated histories. (more complicated).

Here's how you do option A:

cd repo_b
git whatchanged --reverse folder_name
git diff deadb33f HEAD > folder.patch

Above you are determining the point in repo_b's history, where, from that point onwards you want to get all the changes. That commit should be deadb33f.

cd repo_a
git checkout -b new_branch
git reset --hard decafbad

Where decafbad is the commit where the two repos diverged.

patch -p1 < folder.patch
git add changed_folder
git commit -m "changes from repo_b"

This will, however, squash all the changes into one commit. If you want to keep the commit history from repo_b, go with the method I linked to above (option B).

  •  Tags:  
  • git
  • Related