Git: how to push changes made only to certain files?

I recently ran into a problem when I need to select multiple files to move to remote branches using git. In my specific use case, there is only one file created / modified in each individual commit, and I need to programmatically click the selected files (in their last state). I did a little research and found 2 tricks that came close to what I need to do:

  • I can use cherry picking to select specific commits in a new branch and merge this branch into a remote master.
  • I can use rebase -i to reorder the commits, I assume I can change the order so that the commits associated with these selected files are in front, and I can just click the last commit in this list.

For a cherry fence this is a bit confusing. I can create a new branch without all the dirty commits and select the file that is committed to this branch. However, if the file already exists in the branch, it always causes a conflict, which I have to fix manually, and not ideally.

For rebase -i, from what I read, I need to go to the interactive editor where I need to manually reorder the commits, and after that I can start git push to apply everything before commit-SHA (which is reordered). Not perfect, as I have to do manual work.

In general, I think the rebase was close to what I needed, but I could not find an easy way to do this programmatically. Can someone come up with some operations with git analogues that can accomplish my task?

+1
git git-rebase cherry-pick
source share
1 answer

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

Specifying the "them" option in a recursive merge strategy forces conflicts to automatically resolve pure approval of the version in which they are merged. This ignores all conflict warnings, but captures everything that is in commit.

Now I just want to know why cherry-pick might trigger a conflict warning when choosing a commit that changed an existing file in the current branch, even if just adding a line.

+1
source share

All Articles