views:

96

answers:

5

I am familiar with SVN and TFS for source control. One issue which I usually encounter is the same file is modified for different bugs (say bugP is fixed with revision/changeset (N), bugQ is fixed with revision(N+1) and bugR is fixed in revision/changeset(N+2)

Each revision/changeset work on different part of the same file and there is no overlap.

Stakeholders decide that it is important that we include the fix for bugR in the next build but exclude bugP and bugQ fixes.

I understand that this might be a very common scenario. If all the fixes were done in the same branch/trunk, is there a easy way to pull only those revisions which fix a particular bug ?

And does other source control systems like GIT/Mercurial (Hg- is the standard way to say that, I understand) to deal with these kind of issues ?

+1  A: 

Git has the ability to pick out single commits which you want to integrate into your tree. Assuming the bug fixes were separate commits, you can pick and choose which ones you want to apply to your current tree. The command used it cherry-pick.

I presume this is what you've looking for?

I haven't used Mercurial but this answer discusses the issue.

Noufal Ibrahim
A: 

TFS does allow selective merging (merging only certain changesets and/or only certain files within a changeset). When you merge, just choose "Selected changesets" on the first page in the Merge Wizard and then pick the changesets you want to include. To merge only certain files, you can either right click on the file you want to merge and select merge or you can merge a higher level and then undo your checkout of the files you don't want merged (these files will then be available next time you want to merge).

Chris Shaffer
+1  A: 

Git also has the fantastically useful command rebase -i which allows you to select commits to keep or delete from a list. In your example, you should checkout the combined set of changes, and then use

git rebase -i OLDEST_COMMIT_IN_THE_SET^

and then in the following list:

pick 03315fa fix for feature A
pick 2935567 fix for feature B
pick 4d31103 more fixes for feature A
pick 875ca6d fix for feature C
pick f0289e6 undo some broken fixes for feature A
pick 1f84de2 more fixes for feature B

# Rebase 5c50390..1f84de2 onto 5c50390
#
# Commands:
#  p, pick = use commit
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

simply delete the lines corresponding to the commits you don't want - i.e. all lines that don't contain the phrase feature A. Then save the file, quit the editor, and let git do all the work for you.

Alex Brown
Mercurial has this feature as well in the form of the Histedit Extension: http://mercurial.selenic.com/wiki/HisteditExtension
Steve Losh
A: 
Michael Hackner
A: 

With SVN you would create a release branch based on some revision of trunk, and selectively merge in the changes you need there (with cherry picking merges). That also documents what (customer specific) release contains what fixes.

Sander Rijken