How do I merge a sub directory in Git?

前端 未结 6 902
太阳男子
太阳男子 2020-11-27 11:08

Is it possible to merge only the changes for a sub-directory from a local Git branch to a remote Git branch or is it "all or nothing"?

For example, I have:<

6条回答
  •  无人及你
    2020-11-27 12:10

    Use git cherry-pick to select the commits you want and merge only these commits. The key trick here is to get these commits in an easy way (so that you don't have to figure them out by manually checking the Git log and entering them by hand). Here's how: use git log to print the commit's SHA-1 id, like this:

    git log ^  --pretty=format:"%h" --reverse -- 
    

    'commit-a' is the commit immediately before the start point of the branch to merge, and 'commit-b' is the last commit on the branch to merge. '--reverse' prints these commits in reverse order for cherry-picking later.

    Then do it like:

    git cherry-pick $(git log ^  --pretty=format:"%h" --reverse -- )
    

    It is two steps, simple and stable!

提交回复
热议问题