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:
- I can use cherry-pick to pick certain commits into a new branch and merge that branch into the remote master.
- 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?