Various ways to remove local Git changes

前端 未结 9 945
难免孤独
难免孤独 2020-11-27 08:45

I just cloned a git repository and checked out a branch. I worked on it, and then decided to remove all my local changes, as I wanted the original copy.

In short, I

9条回答
  •  爱一瞬间的悲伤
    2020-11-27 09:15

    1. When you don't want to keep your local changes at all.

    git reset --hard
    

    This command will completely remove all the local changes from your local repository. This is the best way to avoid conflicts during pull command, only if you don't want to keep your local changes at all.

    2. When you want to keep your local changes

    If you want to pull the new changes from remote and want to ignore the local changes during this pull then,

    git stash
    

    It will stash all the local changes, now you can pull the remote changes,

    git pull
    

    Now, you can bring back your local changes by,

    git stash pop
    

提交回复
热议问题