dugla
dugla

Reputation: 12954

Git. Rebase local branch atop local master. How do I ignore a single files changes?

With Git I am on a branch. I am rebasing the branch atop master. There is a conflict that I want to resolve by ignoring the branch's version and accepting master's version. How do I indicate I want to use master's version of the file during the rebase?

Upvotes: 12

Views: 14675

Answers (3)

Alex Wolf
Alex Wolf

Reputation: 20148

git checkout --ours <path-to-file> is the command you are looking for.

It will checkout the master version of the file which you then can add to the index (to mark the conflict resolved) and continue your rebase.

You can take a look at the checkout documentation for more information.

See the comment under --merge as to why you need to use --ours and not --theirs.

Upvotes: 17

Valya
Valya

Reputation: 778

Just in case anyone stucks as myself.

If you want to override all your local changes with "theirs", it is probably because someone removed a commit your local branch was referred to and added a new one and you're doing a rebase, so that git tries to apply (this old commit + yours) on top of theirs.

In this case use git rebase -i remote-branch and comment out the old commit.

Hope this helps.

Upvotes: 1

Anjaneyulu Battula
Anjaneyulu Battula

Reputation: 1960

Upvotes: 3

Related Questions