我只需要一个冲突文件的简单列表.
有什么比这简单:
git ls-files -u | cut -f 2 | sort -u
Run Code Online (Sandbox Code Playgroud)
要么
git ls-files -u | awk '{print $4}' | sort | uniq
Run Code Online (Sandbox Code Playgroud)
?
我想我可以为此设置一个方便的别名,但是想知道专业人士是如何做到的.我用它来编写shell循环,例如自动解决冲突等.也许通过插入mergetool.cmd替换该循环?
可能重复:
基于Bash中的分隔符拆分字符串?
在bash脚本中,如何使用分隔符拆分字符串;并在结果数组中循环?
我正在尝试for在shell中使用空格迭代文件名.我在读计算器的问题是IFS=$'\n'可以被使用,这似乎很好地工作.然后,我在评论中读到一个答案,使其与除了可以使用的bash之外的shell兼容IFS=$(echo -e '\n').
前者有效,后者无效.该评论被多次上调.我检查了输出,变量似乎不包含换行符.
#!/bin/sh
IFS=$(echo -e '\n')
echo -n "$IFS" | od -t x1
for file in `printf 'one\ntwo two\nthree'`; do
echo "Found $file"
done
echo
IFS=$'\n'
echo -n "$IFS" | od -t x1
for file in `printf 'one\ntwo two\nthree'`; do
echo "Found $file"
done
Run Code Online (Sandbox Code Playgroud)
输出显示第一个字段分隔符丢失:
0000000
Found one
two two
three
Run Code Online (Sandbox Code Playgroud)
但是第二个是正确的:
0000000 0a
0000001
Found one
Found two two
Found three
Run Code Online (Sandbox Code Playgroud)
我找到了一个已回答的问题,可能与我的问题重复或不同:
linux …