git-stash vs. git-branch

前端 未结 4 1880
一整个雨季
一整个雨季 2021-01-29 19:03

In a previous Git question, Daniel Benamy was talking about a workflow in Git:

I was working on master and committed some stuff and then decided I wanted

4条回答
  •  清酒与你
    2021-01-29 19:10

    'stash' takes the uncommitted, "dirty" stuff on your working copy, and stashes it away, leaving you with a clean working copy.

    It doesn't really branch at all. You can then apply the stash on top of any other branch. Or, as of Git 1.6, you can do:

    git stash branch  []
    

    to apply the stash on top of a new branch, all in one command.

    So, stash works great if you have not committed to the "wrong" branch yet.

    If you've already committed, then the workflow you describe in your question is a better alternative. And by the way, you're right: Git is very flexible, and with that flexibility comes overlapping functionality.

提交回复
热议问题