English 中文(简体)
git: merge a portion of one branch s source tree into another, regardless of individual commits
原标题:

I understand how to merge branches together in git, and I love how easy it makes it.

I have a branch that looks like this:

project/
|--subproj1/
|  |---(files)
|
|--subproj2/
   |---(files)

A colleague has a branch that s made significant changes to both subprojects. More specifically, he s altered them both to depend on a common bit of code in a new subproj3. However, for various reasons, we re not pushing his branch anytime in the forseeable future.

My branch diverges from master only in subproj1, where I m making subproject-specific enhancements. My subproject is less important than some of the others, and thus has less constraints on what types of changes we can push on it. I d like to merge in my colleague s subproj1 changes (and his new subproj3 which those changes depend on) but leave my existing subproj2 alone. Sometime in the future, when he merges his project in entirety to master, I d like his subproj2 changes to merge in normally.

How do I do this with git?

最佳回答

Each commit is a logical unit of work. Unfortunately, that means you cannot separate the edits you colleague has made to subproj1 and subproj2 if he made them on the same branch.

However, to do what you are asking, you would use git filter-branch. You can use this to create a new branch which is defined by replaying all of your colleague s commits but only adding changes to subproj1 to each commit.

The commands are something along the lines of:

git fetch colleague-repo ...
git filter-branch --subdirectory-filter subproj1 -- A..B

(where A..B is the range of commits you fetch from his repository)

By doing this you are creating a unique branch with work that is totally separate from your colleague s work. If you merge this new branch and your colleague s branch into master, the history of changes to subproj1 will permanently be split between the two branches.

问题回答

暂无回答




相关问题
Tracking Versions, Builds, Revisions, with TortiseSVN

I am the sole developer on a project and have been using tortoiseSVN for quite a while. Now Id like to start getting version information working correctly in the project I.E. show Major Version, Minor ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

How to handle different csproj [closed]

I am working in a team of five. We are working on a C# application with five csprojects. The problem is that for each csproject, each of my colleagues has their own ideas on how to reference a DLL; ...

Changing username in SVN+SSH URI on the fly in working copy

I am using SVN+SSH to check out a working copy of repository from an SVN server on which all developers are members of a developer group and have full read/write permissions on the repository ...

How to search for file in subversion server?

Is there a way to search for a file in a subversion repository? Something similar to Unix find command, with which I can find the location of a file in a repository. I know there is svn list, but ...

热门标签