Search code examples
gitgit-rebase

Git Rebase but keeping some changes from feature branch


I have a main branch and a feature_branch.

I did:

git checkout feature_branch
git rebase main

What I want to do is get all changes from main for all files but 1, keep changes done in feature_branch for that file.

How to do that?


Solution

  • What you can do is to simply reset the one odd file back to the original branch before the rebase or merge. You could try:

    git checkout feature_branch
    git log
    # take note of the SHA-1 hash for the HEAD commit (e.g. abcd1234)
    git rebase main
    git checkout abcd1234 -- path/to/file_to_keep.ext
    git commit -m 'Reverted single file to original version'