If I have merge conflicts, how can I take all changes from HEAD for a single file? Not for the whole rebase, but for a single file?
Is this possible, or do I have to manually change it?
Following up on Codrin's answer, yes you can checkout a specific file from HEAD with git checkout HEAD -- path/to/file. However, in general, if you want to checkout a file from the branch being rebased or the branch you're rebasing onto there are the options --theirs and --ours.
When checking out paths from the index, check out stage #2 (
ours) or #3 (theirs) for unmerged paths.Note that during
gitrebaseandgitpull--rebase,oursandtheirsmay appear swapped;--oursgives the version from the branch the changes are rebased onto, while--theirsgives the version from the branch that holds your work that is being rebased.
So, if you need to checkout the version of a file on the branch being rebased, you can use
git checkout --theirs -- path/to/file While, if you need to checkout the version of a file on the branch you're rebasing onto, you can use
git checkout --ours -- path/to/file However, in general, you can use the syntax git checkout <commit_id> -- path/to/file to checkout a certain file version from whatever commit.
You can run git checkout HEAD -- path/to/your/file to reset the file to the state of HEAD. You can also replace HEAD with other identifiers if you want your file to come from other sources e.g. git checkout my-branch -- path/to/file or git checkout HEAD~1 -- path/to/file if you want it to come from 1 commit before HEAD.
When you use KDiff3 to resolve conflicts then what you ask for is trivial because KDiff3 has support for doing exactly that, overriding all automatic and manual conflict resolutions and pick one source specifically (on a per file basis):
And regardless of this specific use case, you should always use a proper 3-way merge tool, like KDiff3, to resolve your conflicts. It is one of those things where once you start using it you will never go back to not using it.