Force “git push” to overwrite remote files

后端 未结 6 1147
情书的邮戳
情书的邮戳 2020-11-22 06:12

I want to push my local files, and have them on a remote repo, without having to deal with merge conflicts. I just want my local version to have priority over the remote one

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 07:02

    Another option (to avoid any forced push which can be problematic for other contributors) is to:

    • put your new commits in a dedicated branch
    • reset your master on origin/master
    • merge your dedicated branch to master, always keeping commits from the dedicated branch (meaning creating new revisions on top of master which will mirror your dedicated branch).
      See "git command for making one branch like another" for strategies to simulate a git merge --strategy=theirs.

    That way, you can push master to remote without having to force anything.

提交回复
热议问题