在bash_profile中添加别名时出现问题


for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \t$branch; done | sort -r

我想添加上面的代码。

我添加了~/.bash_profile,因为我没有~/.bahrc

alias latest="for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \t$branch; done | sort -r"

当我使用它时。

latest
-bash: syntax error near unexpected token `origin/add_material_design_buttons'

预期:

for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \t$branch; done | sort -r
2020-03-10 14:38:39 +0000 15 hours ago  origin/develop
2020-02-25 12:54:43 -0600 2 weeks ago   origin/XXXX1
2020-02-19 15:37:03 -0600 3 weeks ago   origin/XXXX2

更新:

我评论错了,并添加了答案,

alias latest="for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \t$branch; done | sort -r"

source ~/.bash_profile,然后是latest

它仍然显示错误,但当我'source~/.bash_profile'.时可以打印分支

WM-C02WM0T3HTD8:foundation_android zgong$ latest
-bash: syntax error near unexpected token `origin/F11277-MobileFoundation_Analytics_module'
WM-C02WM0T3HTD8:foundation_android zgong$ source ~/.bash_profile
-bash: /Users/zgong/.bash_profile: line 19: syntax error near unexpected token `origin/F11277-MobileFoundation_Analytics_module'
-bash: /Users/zgong/.bash_profile: line 19: `for branch in   origin/AddLoggerModule
origin/F11277-MobileFoundation_Analytics_module
origin/F12172-MobileFoundation-ProfilingService
...
origin/upgradeMissingKotlinVersion
origin/zakavila/android_build_scripts_test;do echo -e 2020-03-10 14:38:39 +0000 2 days ago t; done | sort -r '

当我打开一个新的终端,并在另一个回购中键入"最新"时,它就起作用了。

为什么我需要关闭现有的iTerm终端,而必须打开一个新的终端才能使其工作?

这里尝试一个函数。

latest(){ for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \t$branch; done | sort -r; }

运行

latest
  • 别名不接受参数

像这样重写

alias latest='for branch in $(git branch -r | grep -v HEAD); do printf "$(git show --format="%ci %cr" $branch | head -n 1)t$branchn"; done | sort -r'

最新更新