Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我git branch在命令行上执行时,我得到一个 repo 上所有分支的列表,但是当我$(git branch)在子 shell 中执行时,它首先打印出 repo 中顶级文件夹中的文件列表,然后再打印出分支名字。为什么?
git branch
$(git branch)
我基本上是在尝试使用 for 循环遍历分支,但是文件列表破坏了我的脚本。
for i in $(git branch); do echo $i done
$ git branch * master
试试echo * master你的shell,看看你得到了什么?
echo * master
提示:您将从*.
*
有关详细信息,请参阅DontReadLinesWithFor。
因为您的第一个分支(或签出的分支)*旁边有一个,它是一个 shell 通配符。这正在评估并扩展到当前目录中的文件列表。
尝试在列表下方检出一个分支,您会发现要插入的文件列表移动到当前检出分支旁边的列表中,而不是在顶部。