Git merge while discarding any previous changes(In local repository or from the last commit)

后端 未结 3 1675
闹比i
闹比i 2021-01-23 11:43

In Git, during a merge, is there a way that we can tell git to discard local changes in case of a conflict and apply the changes from the merged branch?

I mean if there

3条回答
  •  渐次进展
    2021-01-23 12:32

    Before trying to merge, you can discard the local changes yourself git reset --hard HEAD.
    You can replace HEAD by whatever commit hash you want.
    This will bring you the the clean state of the commit you're actually on, and you'd lose all your changes.

    If you want to keep them, you can stash them before with git stash, or move them to another branch:

    git checkout -b new_branch
    git add .
    git commit -m "My awesome commit"
    git checkout - # will bring you back to the last branch you were in
    

提交回复
热议问题