1

I recently ran into a problem where I need to select a few files to push to remote branches with git. My specific use case here is there is only one file created/modified in every single commit, and I need to programatically push the selected files (in their latest state). I did a bit of research and found 2 tricks that came close to what I need to do:

  1. I can use cherry-pick to pick certain commits into a new branch and merge that branch into the remote master.
  2. I can use rebase -i to reorder the commits, I assume I can reorder so that the commits relating to those selected files are all in front and I can just push the last commit in that list.

For cherry-pick it is a bit confusing. I can create a new branch without all the dirty commits and pick the file commits into that branch. However if the file already exists in the branch, it always throws a conflict that I have to fix manually, not ideal.

For rebase -i, from what I have read I need to goto an interactive editor where I need to manually reorder the commits, and after that I can do a git push origin to apply everything up to the commit-SHA (which is reordered). Not ideal since I have to do manual work.

Overall I think rebase came closer to what I need, but I couldn't find an easy way to do it programatically. Can anyone come up with some git analogy operations that can accomplish my task?

Xavier_Ex
  • 8,432
  • 11
  • 39
  • 55
  • Let me get this straight - there are a bunch of commits on one branch that you need to apply to another, and in each commit there is only one file which is modified. So maybe commit 1 modifies file A, commit 2 modifies file B, etc? – Adam S Apr 11 '13 at 02:36
  • @AdamS Yes what you said is correct, but there could be a bunch of commits modifying the same file. Let's say I have C1, C2, C3, C4, and C2 modified file A, all the rest modified file B. Now I want to push modification of file B (namely C1, C3, C4). I know rebase -i can do this but please refer to my main post (there isn't a programatic way). – Xavier_Ex Apr 11 '13 at 14:13

1 Answers1

1

I think I have found the solution to this problem: cherry-pick --strategy=recursive -Xtheirs <commit-SHA>.

Specifying the 'theirs' option in recursive merge strategy forces conflicts to auto-resolve cleanly favoring the version that's being merged in. This will ignore all the conflict warning but grab whatever is in the commit.

I guess now I just want to know why cherry-pick would produce a conflict warning when picking a commit that modified an existing file in the current branch, even if just adding a line.

Xavier_Ex
  • 8,432
  • 11
  • 39
  • 55