Git merge folder by folder?

I have 2 branches “master” and “slave”, both branches did alot of changes. While merging, some folder need to be overwrite, some need to solve conflicts and some can just merge normally. What I wish is merge them part by part, folder by folder.

Step 1:
Merging “master” to “slave”, so I checkout branch “slave”…

git checkout slave

Step 2:
FolderA, FolderB, FolderC need to be overwrite with the folders in “master”, so what I did is…

git checkout master FolderA
git checkout master FolderB
git checkout master FolderC
git commit -am "Overwrite with master"
git push origin slave

Step 3:
FolderD, FolderE, FolderF are folders that will have conflicts, I wish I could do merge them one by one. Then use git mergetool to solve conflicts, something like…

(git merge master FolderD)?
git mergetool

But that will give me a error “fatal: ‘FolderD’ does not point to a commit”.

Step 4:
FolderG to FolderZ have changes that doesn’t have conflicts, so just merge normally.

git merge master

The conflicts will be complicate and need times to solve, thats why I wish to do it one by one, how do I achieve step 3 and be able to proceed to step 4?

  • Github Branch,Tag: How to get a specific release of a code?
  • Can I push hotfix to a tag in git
  • Splitting one Git repository into many - branches become forks
  • How do I move recent (but not latest) commits to a new branch
  • Commit a single file to another branch
  • How can I color Git branches based on their names?
  • Does “-u” in “git push -u origin master” add a reference to a remote tracking branch?
  • git add remote tracking branch to bare repo
  • One Solution collect form web for “Git merge folder by folder?”

    Here’s one way I would do it. Give it a try and see if it does what you want.

    git checkout slave
    git merge master
    git checkout --theirs FolderA FolderB FolderC
    git add FolderA FolderB FolderC

    Now you’ll be in a state, given your example, where conflicts will be left in FolderD through FolderZ which you can resolve and git add. This should give you what you are asking for.

    The only direct problem I see is your statement that you would like to resolve the conflicts one folder at a time. The problem here is that Git’s first layer is the commit which can span multiple folders at once.

    One nice thing about this approach is that Git’s history is maintained, whereas your proposed approach would destroy the history as you would be making a new, non-merge, commit for FolderA through C.

    Another approach you might want to explore is using git filter-branch to semi-automatically rewrite each commit in a branch. This will give you the ability to selectively accept and reject changes from each commit, allowing you to programmatically filter FolderA through Z as you see fit. Take a look at:

    Git Baby is a git and github fan, let's start git clone.