Can I tell git pull to overwrite instead of merge?

后端 未结 3 702
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 07:20

As far as I see, git pull someRemote master tries to merge the remote branch into mine.

Is there a way to say \"Completely discard my stuff, just make m

相关标签:
3条回答
  • 2020-12-14 07:44

    If you want to keep your current master branch but register a new version (mirroring the remote branch), you can;

    • register a merge filter driver (just for this merge: a keepTheir one)
    • do a git pull --no-commit
    • check if there aren't extra files that need to be removed (files in your master that were not present in the remote branch)
    • commit
    0 讨论(0)
  • 2020-12-14 07:49

    Sounds like you're after git checkout, which will discard your local changes to a path.

    You can revert your changes using checkout:

    git checkout myfile.h
    

    will restore myfile.h from the index

    http://git-scm.com/docs/git-checkout

    0 讨论(0)
  • 2020-12-14 07:51

    First, rename your master branch to something else:

    git branch -m master my_old_master
    

    Then, create a new master:

    git checkout -b master someRemote
    

    The great thing about Git's branch names is that they aren't actual places themselves, they're just pointers to places (where a "place" is a SHA1 commit id).

    0 讨论(0)
提交回复
热议问题