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:
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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.