Switching a branch after aborting current changes in git

前端 未结 9 1383
情书的邮戳
情书的邮戳 2021-01-30 17:00

I cloned a git repo and then started playing around in its master branch. After a while, I want to ignore the changes I just made (without committing them), and switch to a diff

9条回答
  •  鱼传尺愫
    2021-01-30 17:32

    Just for the sake of completeness, and for those who landed here by searching: Although the OP asks specifically for a solution without stashing, it is worth mentioning that stash is indeed a very nice option:

    The command saves your local modifications away and reverts the working directory to match the HEAD commit.

    So you can simply

    git stash
    

    This is like resetting to HEAD. When being absolutely positively certain that indeed those uncommitted changes are worthless, simply

    git stash drop
    

    You can even have multiple stashes etc. as mentioned in the documentation link above.

    I would recommend this practice since it puts one in the habit to double-think before resetting without a significant cost.

提交回复
热议问题