Various ways to remove local Git changes

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

    I think git has one thing that isn't clearly documented. I think it was actually neglected.

    git checkout .

    Man, you saved my day. I always have things I want to try using the modified code. But the things sometimes end up messing the modified code, add new untracked files etc. So what I want to do is, stage what I want, do the messy stuff, then cleanup quickly and commit if I'm happy.

    There's git clean -fd works well for untracked files.

    Then git reset simply removes staged, but git checkout is kinda too cumbersome. Specifying file one by one or using directories isn't always ideal. Sometimes the changed files I want to get rid of are within directories I want to keep. I wished for this one command that just removes unstaged changes and here you're. Thanks.

    But I think they should just have git checkout without any options, remove all unstaged changes and not touch the the staged. It's kinda modular and intuitive. More like what git reset does. git clean should also do the same.

提交回复
热议问题