Various ways to remove local Git changes

前端 未结 9 953
难免孤独
难免孤独 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:17

    As with everything in git there are multiple ways of doing it. The two commands you used are one way of doing it. Another thing you could have done is simply stash them with git stash -u. The -u makes sure that newly added files (untracked) are also included.

    The handy thing about git stash -u is that

    1. it is probably the simplest (only?) single command to accomplish your goal
    2. if you change your mind afterwards you get all your work back with git stash pop (it's like deleting an email in gmail where you can just undo if you change your mind afterwards)

    As of your other question git reset --hard won't remove the untracked files so you would still need the git clean -f. But a git stash -u might be the most convenient.

提交回复
热议问题