2

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 "?

stsquad
  • 5,712
  • 3
  • 36
  • 54
  • you should've used different branches or even repositories for those directories, not just duplicate the data in the repository. Good luck with your messy repository. – KurzedMetal Apr 13 '12 at 16:45
  • @KurzedMetal: unfortunately there is a requirement to build both versions of the mgmt-app out of the same system release. This is because a common code base is used for the management software (which can talk to multiple devices) as the system software (which of course only manages itself). Such messiness is often due to compromises needed to release actual products. – stsquad Apr 16 '12 at 12:11
  • If I were you, I'd keep both `mgmt` directories in different branches in one repository (to be able to merge or cherrypick between them) and the common code in another repo. Then I'd import both `mgmt` directories into the common code using `git submodule`or viceversa (import the common code into each `mgmt` directory), whatever you need. – KurzedMetal Apr 16 '12 at 13:42

2 Answers2

1

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.

Abe Voelker
  • 30,124
  • 14
  • 81
  • 98
0

Use git cherrypick

KurzedMetal
  • 12,540
  • 6
  • 39
  • 65
  • I think you have misunderstood the problem. These are commits in the same branch. Reading the man pages I can't see how to translate the cherry picks to a new directory in the same tree. – stsquad Apr 13 '12 at 15:58
  • git commits != diffs, when you say "apply a git commit to another party of my tree" it refers to the commit tree and not the filesystem tree. That's what cherrypick does, copy commits from one part of the commit tree to another, i think you made the wrong question. – KurzedMetal Apr 13 '12 at 16:42