简体   繁体   中英

If I create a branch after typing git stash branch what happens?

Specially, after I typed

git stash branch

I typed

git status

which returned this:

## HEAD (no branch)
?? Project/Setup_BACKUP_38164.swift
?? Project/Setup_BASE_38164.swift
?? Project/Setup_LOCAL_38164.swift
?? Project/Setup_REMOTE_38164.swift

I now want to create a new branch that is the same as my stash. I'm wondering if I type

git checkout -b *newbranchname

From where I currently am in HOME, will this new branch be equal to my stash? Or would I need to do a commit of some sort? Why is the commit necessary if so?

Thanks!

git stash branch <branchname> [<stash>] Creates and checks out a new branch named <branchname> starting from the commit at which the <stash> was originally created, applies the changes recorded in <stash> to the new working tree and index. If that succeeds, and <stash> is a reference of the form stash@{<revision>}, it then drops the <stash>. When no <stash> is given, applies the latest one.

As per the docs, git stash branch creates and checks out the branch for you. After this command you don't have to explicitly checkout any branch

If you run your command as you said: "git stash branch" you should have gotten an error or end up with a strange situation. First you can do:

git branch

to check in which branch you are right now, if you don't like this branch just checkout the one of interest, then:

git status

to see if you have unsaved changes (not committed), from there you should be able to tell if your previously stashed changes are applied or not in your current status, if they are applied from there you can create your new branch:

git checkout -b "Name of your new branch" 

and you are good.

If you can't see your stashed changes then do:

git stash list

and notice the number between curly braces that identify the set of changes you are interested on, in this case you do:

git checkout -b "Name of your new branch"
git stash apply {"The Number of stash of interest"}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM