Switching a branch after aborting current changes in git

前端 未结 9 1480
情书的邮戳
情书的邮戳 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:29

    To ignore but NOT remove the changes

    OP asks to ignore changes - but does not ask to remove them. Sounds like OP want changes to still be around. So this answer is for those folks in a similar situation who don't want to lose their changes.

    Given the limitations encountered already, plus given you want to keep those changes, one option is to put them in another branch

    Regardless of where you have either uncommitted or staged changes, you can always make a new branch with

    git checkout -b new_branch
    

    and then git add and git commit as necessary. and now you can switch to other branches at will, knowing these changes have been saved.

    Like the OP I don't like to use stash and pop (and cherry pick) but isolating these changes by putting them into a new branch I can then merge and rebase to and from works well for me. Using branches for the solution is easy for me

提交回复
热议问题