简体   繁体   中英

Git Pull With Ignoring Remote Changes in Conflicted Files

I want to git pull from the remote origin and want to keep my local changes and want to ignore remote changes in conflicted files only. Is there any way to do it by Git?

I have one option that I backup my local files and after pull, override them with the conflicted files. But I want to achieve this by using git.

Instead of git pull , You can use git rebase to resolve conflict. It will not merge remote code into your branch, instead it will give one by one step to resolve conflicts.

With stash and merge this should work (I don't know if you want call this a dirty solution 😉):

  1. git stash
    Stash current changes (Maybe you need --include-untracked too)
  2. git pull
    Pull remote changes
  3. git merge -X theirs --no-commit --no-ff stash
    Merge stash into current branch (with changes from stash applied), don't commit and fast-forward
  4. git reset -- .
    Unstage changes
  5. git merge --abort
    Abort the merge operation
  6. git stash pop in case you need your untracked files too

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM