准备工作
- 查看当前git命令执行目录
<code>which git/<code>
- 查看执行目录下git相关软连接
<code>ls -lrt /usr/local/bin/git*/<code>
- 查看git安装目录下git相关命令ls -lrt /usr/local/bin/git*
<code>ls -lrt /usr/local/bin/git*/<code>
在git安装目录添加扩展命令文件
<code>git-first
#!/bin/sh first() { branch=refs/heads/master git log --reverse --pretty=%H $branch | head -1 | xargs git checkout } first "$@" /<code>
<code>git-last
#!/bin/sh last() { branch=refs/heads/master git log --pretty=%H $branch | head -1 | xargs git checkout } last "$@" git-prev#!/bin/sh prev() { branch=refs/heads/master if [ -z "$1" ]; then n=1 else n=$1 fi git checkout HEAD~$n } prev "$@" git-next#!/bin/sh next() { branch=refs/heads/master if [ -z "$1" ]; then n=1 else n=$1 fi git log --reverse --pretty=%H $branch | grep -A $n $(git rev-parse HEAD) | tail -1 | xargs git checkout } next "$@"/<code>
<code>git-prev
#!/bin/sh prev() { branch=refs/heads/master if [ -z "$1" ]; then n=1 else n=$1 fi git checkout HEAD~$n } prev "$@" /<code>
<code>
/<code>
- 分别为新建命令文件添加执行权限
<code>chmod 755 git-first
chmod 755 git-last
chmod 755 git-prev
chmod 755 git-next/<code>
- 在/usr/local/bin目录下建立软连接
<code>ln -sf ../Cellar/git/2.23.0_1/bin/git-first git-first
ln -sf ../Cellar/git/2.23.0_1/bin/git-last git-last
ln -sf ../Cellar/git/2.23.0_1/bin/git-prev git-prev
ln -sf ../Cellar/git/2.23.0_1/bin/git-next git-next/<code>
- 在git仓库目录下查看作者的commit
<code>git first git last git prev git next/<code>
Good luck.
閱讀更多 Gopher 的文章