![](/img/trans.png)
[英]Pipe output from command in Git Bash to Powershell script on windows
[英]How can I pipe output from git log in Git Bash?
原因:我想使用difftool比較兩個任意不同的提交。 我從搜索中知道哈希,並且我不想復制這些哈希,因此我正在尋找一個執行類似操作的命令
$ log_str=$(git log --all -S"new_tour <-" --pretty=format:"%h")
$ git difftool -t kdiff3 log_str[1] log_str[2] myfile.txt
log_str
的結構,那將是log_str
的。 是角色嗎? 字符數組? 一個列表? ...使用重擊。 我在這里和這里找到了一些相關的幫助,但是我無法使它起作用。
現在我做:
$ git log --pretty=format:"%h"
3f69dc7
b8242c6
01aa74f
903c5aa
069cfc5
和
$ git difftool -t kdiff3 3f69dc7 b8242c6 myfile.txt
我將使用臨時文件采取兩步方法:
git log --all -S'SEARCH' --pretty=format:"%h" > tmp_out
git diff "$(sed -n '1p' tmp_out)" "$(sed -n '2p' tmp_out)" myfile.txt
rm tmp_out
sed用於顯示文件的第1行和第2行。
帶有變量:
search="foo"
index_a="1"
index_b="2"
file="myfile.txt"
git log --all -S"${search}" --pretty=format:"%h" > tmp_out
git diff "$(sed -n "${index_a}p" tmp_out)" "$(sed -n "${index_b}p" tmp_out)" "${file}"
rm tmp_out
在bash函數中:
search_diff() {
search="${1}"
index_a="${2}"
index_b="${3}"
file="${4}"
git log --all -S"${search}" --pretty=format:"%h" > tmp_out
git diff "$(sed -n "${index_a}p" tmp_out)" "$(sed -n "${index_b}p" tmp_out)" "${file}"
rm tmp_out
}
search_diff "foo" 2 3 myfile.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.