stsquad
stsquad

Reputation: 6030

Is there a way to apply git commits from one part of my tree into another?

In the dim and distant past there was a decision to break compatibility with one of our configuration programs. However as there would still be remote units running older software we needed to keep a version of the old mgmt software around in the build. A short "cp -a" later we ended up with a directory structure containing:

mgmt-app
mgmt-app.old

Development continued and mgmt-app accumulated a number of fixes, some to new functionality and some generic functionality. As you can probably guess it is now noted that mgmt-app.old doesn't have some of these fixes. It would be nice if I could cherry-pick the relevant fixes and keep useful stuff like comments but apply the commits to mgmt-app.old. Obviously they don't apply normally as they are already in the tree applied to the mgmt-app!

We are using git to version control the repository. Is there a way I could "backport" these commits to a different part of the tree? Is this just going to be solved by manually applying patches with "patch -p "?

Upvotes: 2

Views: 176

Answers (2)

Abe Voelker
Abe Voelker

Reputation: 31594

Start a new branch for your "old" stuff:

git checkout -b old

Using gitk, go back through your history and find out the commit right before mgmt-app.old was created. Identify the SHA1 of that commit, and

git reset --hard <sha1>

to make your old branch point there. Now you have a branch for when development diverged, and you can do an interactive rebase (git rebase -i) to cherry pick (and edit, if needed) commits from your new/current development branch to this old one.

Upvotes: 1

KurzedMetal
KurzedMetal

Reputation: 12946

Use git cherrypick

Upvotes: 0

Related Questions