Do a Git pull to overwrite local changes

前端 未结 2 1072
[愿得一人]
[愿得一人] 2021-01-31 12:26

There has certainly been posts around for this, but I actually did a commit because I thought it was the right thing to do.

So, I have two repositories, one development

相关标签:
2条回答
  • 2021-01-31 12:56

    You need to push from production first to GitHub:

    git push origin yourbranch --force
    

    The force will make sure that GitHub has what production has.

    Here are the possibilities of what you could do:

    You will need to fetch the changes into your development repository in the deploy repository. At this point you will see that the history is branching (via git log --all --graph or gitk --all).

    git fetch origin
    

    You can now rebase or merge to get your latest changes to be subsequent to the ones made on the production repository. This will enable you to push changes to your deploy repository at a later point.

    The conflicts are there for a reason. Look at them and resolve them, add and commit.

    If you want the conflicts to be resolved by taking what is on the production side you can use the "recursive theirs" strategy:

    git merge -s recursive -Xtheirs production/yourbranch
    

    If you want to take no changes from your side, merge normally, but when stopped at the conflicts, get the other side of the merge, add and commit.

    git merge production/yourbranch
    git checkout production/yourbranch -- .
    git submodules update #this is optional and can be skipped if you don't have any submodules
    git add -A
    git commit
    

    Now subsequent pushes to GitHub from development and pulls from GitHub in production will work.

    You could reset the branch, but that assumes that you don't want to keep any changes that you made on the development repository.

    git reset --hard production/yourbranch
    
    0 讨论(0)
  • 2021-01-31 12:59

    If you want to entirely replace your local branch foo with the contents of the remote branch origin/foo:

    git fetch origin
    git checkout foo
    git reset --hard origin/foo
    

    If you want to do something else, please reword your question. However, I might add the production Git repository as a remote and then merge the live changes in, instead of whatever you tried.

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