使用格式创建'git log'别名

编程入门 行业动态 更新时间:2024-10-22 21:24:08
本文介绍了使用格式创建'git log'别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经在我的.bash_profile中设置了一堆git别名,它们可以正常工作:

别名gst =git状态别名gl =git pull别名gp =git push别名gd =git diff | mate别名gc =git commit -v 别名gca =git commit -v -a别名gb =git branch别名gba =git branch -a

我试图给以下命令添加一个别名,但仍然遇到错误:

git log --all --pretty = format:'%h%cd%s(%an)'--since ='7 days ago'

我想要做的是能够输入:

glog'一段时间'

新的在别名和混帐,我想这会工作:

alias glog =git log --all --pretty =格式:'%h%cd%s(%an)'--since =

出现以下错误:

fat al:7天前的模棱两可的论点:未知的版本或路径不在工作树中。 使用' - '分隔修订版本的路径,如下所示:'git< command> [< revision> ...] - [< file>]'

如何纠正我的别名,使其工作?

谢谢!

/ strong>

如果我将别名更改为:

alias glog =git log --all --pretty = format:'%h%cd%s(%an)'

,然后输入:

glog --since ='一定数量的时间'

但我真的很想只输入时间量,如果可能的话。并像往常一样称呼:

glog7天前

code>

快速追踪:我将如何变更允许$​​ b $ b可能性的函数还附加了--author =so-and-so标志?例如,I 可以输入glog7天前或博客7天前--author =bob

glog() { if [-z $ 2];然后 git log --all --pretty = format:'%h%cd%s(%an)'--since =$ 1 else git log --all - -pretty = format:'%h%cd%s(%an)'--since =$ 1--author =$ 2 fi }

glog7天前 glog7天前bob

请注意, if [-z$ 2];那么条件是检查第二个参数是否为空。如果是这样,只需执行没有 author 的代码。否则,它会使用它。

I have a bunch of git aliases already set up in my .bash_profile that work correctly:

alias gst="git status" alias gl="git pull" alias gp="git push" alias gd="git diff | mate" alias gc="git commit -v" alias gca="git commit -v -a" alias gb="git branch" alias gba="git branch -a"

I'm trying to add an alias for the following command, but keep running into an error:

git log --all --pretty=format:'%h %cd %s (%an)' --since='7 days ago'

What I'd like to do, is be able to type:

glog 'some amount of time'

So, being new at both aliases and git, I figured this would work:

alias glog="git log --all --pretty=format:'%h %cd %s (%an)' --since="

It throws the following error:

fatal: ambiguous argument '7 days ago': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]'

How can I correct my alias to make this work?

Thanks!

[EDIT]

I can make it work if I change the alias to:

alias glog="git log --all --pretty=format:'%h %cd %s (%an)'"

and then just type in:

glog --since='some amount of time'

but I'd really like to just type the amount of time, if possible.

解决方案

Instead, you can create a function in .bash_profile. It will allow you to use variables:

glog () { git log --all --pretty=format:'%h %cd %s (%an)' --since="$1" }

And call it like usual:

glog "7 days ago"

quick follow-up: how would I change the function to allow the possibility of also appending the --author="so-and-so" flag? as in, I could type glog "7 days ago" or blog "7 days ago" --author="bob"

I would do as like follows:

glog () { if [ -z "$2" ]; then git log --all --pretty=format:'%h %cd %s (%an)' --since="$1" else git log --all --pretty=format:'%h %cd %s (%an)' --since="$1" --author="$2" fi }

So you can call it with

glog "7 days ago" glog "7 days ago" "bob"

Note that the if [ -z "$2" ]; then condition is checking if the second parameter is empty. If so, just executes the code without author. Otherwise, it uses it.

更多推荐

使用格式创建'git log'别名

本文发布于:2023-10-26 18:59:27,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:别名   格式   git   log

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!