通过换行符拆分 git diff --name-status
我正在尝试使用 git 使用以下命令导出两次提交中已更改文件的列表:
read -ra ADDR <<< `git diff --name-only HEAD..HEAD~1 | sed -e "s/ /\\\ /g"`
for i in "${ADDR[@]}"; do
echo "$i"
done
这工作正常。我得到了一个很好的列表,打印到终端,每个文件都在新行上。
file1.txt
file2.txt
file3.txt
但是,我想使用 --name-status
而不是 --name-only
。原因是这样我以后可以根据所做的更改类型(例如 M 或 D)做不同的事情。
但这不起作用。我得到以下格式的列表:
M
file1.txt
M
file2.txt
M
file3.txt
我尝试将 IFS
变量更改为 $'\n'
(返回一行上的所有内容),$' \t'
(返回第一行,例如 M file1.txt
)和 '
(与 \t
相同)没有成功。
I'm trying to export a list of changed files from two commits with git, with this command:
read -ra ADDR <<< `git diff --name-only HEAD..HEAD~1 | sed -e "s/ /\\\ /g"`
for i in "${ADDR[@]}"; do
echo "$i"
done
This works fine. I get a nice list printed out to the terminal with each file on a new row.
file1.txt
file2.txt
file3.txt
However, I want to use --name-status
instead of --name-only
. The reason is so I can later do different things depending on what kind of change was made (e.g. M or D).
This doesn't work though. I get a list in the following format:
M
file1.txt
M
file2.txt
M
file3.txt
I have tried to changed the IFS
variable to $'\n'
(returns everything on one row), $'\t'
(returns first row, e.g. M file1.txt
) and ' '
(same as \t
) without success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
例如,对于 git 输出,
由 while 循环打印如下所示:
E.g. for git output like
the following is printed by the while loop: