0

In master branch I have below commits:

A-B-C-D-HEAD

In branch "test" I have:

A

I did:

git cherry-pick <SHA FOR COMMIT C>

However, I don't want commit B on "test" branch. How can I ignore that? so that test branch end up like: A-C

Sara
  • 2,308
  • 11
  • 50
  • 76
  • 1
    Do you only want commit C on the test branch? Or A and C on the test branch? – Sam-Graham Oct 01 '14 at 05:36
  • 2
    You need to edit your question to show where your test branch is relative to the other commits. – Andrew C Oct 01 '14 at 05:37
  • If you all did is `git cherry-pick ` when the `HEAD` of `test` is still pointed at `A` (i.e. you didn't do any merge), you should only end up with just `A-C`. – ivan.sim Oct 01 '14 at 05:43

2 Answers2

4

You can do this: (Assuming master points to D)
1. (master) git-checkout -b test
2. (test) git rebase -i
You will have a list of commits like:

pick b6e7d38 A
pick 263b0cc B
pick 6bcea1d C
pick 6kdf8gd D

Just delete the commit that you don't want (B and D here). Save and continue, It will be omitted while rebasing.

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Garima
  • 174
  • 6
  • If she rebases and removes the commits, they will be gone for good from master. She wants them on master but not on test. – Mudassir Razvi Oct 01 '14 at 07:10
  • Sorry but I don't agree with your point.Please refer this below doc You can combine your commits by rebase and squash the ones you dont need. Refere this: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html – Garima Oct 01 '14 at 07:50
  • I agree, your approach was perfectly alright but on a wrong branch. If you rebase the master branch and delete D and B, then they will be gone for good. You approach is correct if she did that while on test branch where test has originated from master pointing to D. I edited the answer as rebase -i master would have been messy for her – Mudassir Razvi Oct 01 '14 at 09:30
0

The best option according to me would be git format-path.

Step1: (master) git format-patch -2
Step2: (master) git checkout -b test <SHA of Commit-A>
Step3: (test) git am 0002-Commit-Msg-of-C

You are good to go!

Explanation: Step1 will create 2 patch-files, one for commit D and one for C. In Step3 you are applying the patch(changes) made while commit-C over A(test points to A, step2)

Hope this helps!

PS: This will work if your changes in B are unrelated to changes in C.

Mudassir Razvi
  • 1,783
  • 12
  • 33