Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to git patch a subrange of a branch?

Tags:

In Subversion, it is easy to merge a range of changesets/diffs from a branch using "svn merge -r a:b mybranch". But in git, I found it is only possible to cherry-pick a single commit from a branch to apply that patch to my current working branch. So I am wondering if there is a fast way to apply all the commits in one swoop between two tags in a bugfix branch to my current master branch?

like image 230
jscoot Avatar asked Feb 04 '09 02:02

jscoot


People also ask

How do I cherry pick a git patch?

8 Answers. Show activity on this post. git cherry-pick -n <commit> # get your patch, but don't commit (-n = --no-commit) git reset # unstage the changes from the cherry-picked commit git add -p # make all your choices (add the changes you do want) git commit # make the commit!

What is git format patch?

Patch is a text file, whose contents are similar to Git diff, but along with code, it also has metadata about commits; e.g., commit ID, date, commit message, etc. We can create a patch from commits and other people can apply them to their repository.


1 Answers

The easiest way to perform the action that you are looking for is with git rebase. Here's a recipe. Assume that tag A is the commit on top of which the patch series that you want to select is based and that tag B is the commit of the final patch in the series. Also, assume that br is the name of the current branch and the branch where the new patch series should be applied.

# Checkout a new temporary branch at the current location git checkout -b tmp  # Move the br branch to the head of the new patchset git branch -f br B  # Rebase the patchset onto tmp, the old location of br git rebase --onto tmp A br 
like image 90
CB Bailey Avatar answered Sep 24 '22 07:09

CB Bailey