使用 git,我在 master 分支上工作并且有一些未添加和未提交的文件。我不想添加它们或将它们提交给主人。相反,我试图隐藏文件并移动到一个新分支以添加它们并在那里提交它们。但是,这失败并显示错误消息:“未找到藏匿处。”。请看下面的日志:
$git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: Makefile
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# newfile.c
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)
然后当我尝试使用 git stash
$git stash branch mywork
No stash found.
Run Code Online (Sandbox Code Playgroud)
我很确定我以前以类似的方式使用过 git stash,但我不明白为什么它现在失败了。如何将我的更改存储到另一个分支并在那里提交?
该git stash branch命令从现有的存储中创建一个新分支。因为您还没有现有的存储,所以您会收到错误消息。
只需使用git stash,然后,如果您想从此存储创建一个新分支,git stash branch mywork.