git stash - 防止执行拼写错误的子命令

标签 git git-stash

git stash documentation ,有这样一段:

For quickly making a snapshot, you can omit "push". In this mode, non-option arguments are not allowed to prevent a misspelled subcommand from making an unwanted stash entry. The two exceptions to this are stash -p which acts as alias for stash push -p and pathspecs, which are allowed after a double hyphen -- for disambiguation.

突出显示的句子到底是什么意思? 我认为可以使用的唯一非选项参数是 <message><pathspec>... .

这是否意味着如果有人写命令 git stash -m"message" ,git 可能认为用户拼错了单词 stash ,但它仍然执行命令( git stash push )?

谢谢。

最佳答案

据我了解,它与 git stash save 的典型行为有关。

如果你这样做

git stash save whatever you want

然后每个参数(“无论”、“你”和“想要”)都将被视为一个整体来组成 stash 消息。 (注意:存储保存已弃用)

现在,由于 git stash Push 允许省略 push,您以粗体引用的语句使我们刚刚看到的行为“清楚”(显然还不够)关于 git stash save 不适用。此处不允许其他非选项参数。

简而言之,我们不能做的一个例子:

git stash whatever I want

其中push将隐含在stash之后。

或者更具体地说(解决“拼写错误”部分):

# next command will create a new branch with the last stashed content
git stash branch myNewBranch

# and the next WOULD HAVE created a new stash entry with message "brnach myNewBranch"
# if not for the part you quoted in bold
git stash brnach myNewBranch

评论后编辑:但是最后一个拼写错误的行将被错误地拒绝,而不是无意中 stash 任何内容。

关于git stash - 防止执行拼写错误的子命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51782434/

相关文章:

bash - 考虑到标准 Git 排除,列出所有跟踪和未跟踪的文件

git - 终端无法识别 $ 命令

git - 如何在 git 中组合多个存储

git - stash 对特定文件的更改

git - 是否有最大数量的 git stashes?

git - 如何对多个文件并行运行递归查找和替换操作?

git - 切换到另一个分支(如果不存在则创建),而不检查是否已经存在?

几天前创建的分支的 Git rebase

git create stash 无需配置 user.email 和 user.name (git stash --author ?)

git - 如何为多个提交更改 'git stash'?