File tree Expand file tree Collapse file tree 8 files changed +85
-10
lines changed Expand file tree Collapse file tree 8 files changed +85
-10
lines changed Original file line number Diff line number Diff line change 2
2
3
3
Treat git log as a book, exec ` git next ` or ` git prev ` to checkout the next or the previous commit.
4
4
5
- ### 像翻页一样跳转到上一(n)条或下一(n)条 Git 历史节点
5
+
6
+ ## How to install?
7
+
8
+ 1 . Clone this repository
9
+ 2 . Execute command : ` ./install.sh `
10
+
11
+ or
12
+
13
+ 1 . Download the ` git-paging-alias.txt `
14
+ 2 . Execute ` git config --global --add include.path PATH/git-paging-ali.txt `
15
+
16
+ ## Git alias guidelines
17
+
18
+ 1 . ` git hist [<BRANCH_NAME> or <revision-range> [<options>]] ` - show all history commits
19
+ 2 . ` git swc-first ` - switch the first commit
20
+ 3 . ` git swc-last ` - switch the last commit
21
+ 4 . ` git swc-prev ` - switch previous commit
22
+ 5 . ` git swc-next ` - switch next commit
23
+
24
+ ## 像翻页一样跳转到上一(n)条或下一(n)条 Git 历史节点
6
25
7
26
请查看博客文章 [ 阅读开源代码小技巧] ( https://hutusi.com/git-paging ) 获得更多使用帮助。
27
+
Original file line number Diff line number Diff line change 1
1
#! /bin/sh
2
2
3
3
first () {
4
- branch=` git symbolic-ref refs/remotes/origin/HEAD`
5
- git log --reverse --pretty=%H $branch | head -1 | xargs git checkout
4
+ REMOTE=$( git remote)
5
+ branch=${1:- $(git symbolic-ref " refs/remotes/$REMOTE /HEAD" )}
6
+ git log --reverse --pretty=%H " $branch " | head -1 | xargs git checkout
6
7
}
7
8
first " $@ "
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+
3
+ hist () {
4
+ if test -z $1 ; then
5
+ REMOTE=$( git remote)
6
+ params=${1:- $(git symbolic-ref " refs/remotes/$REMOTE /HEAD" )}
7
+ else
8
+ params=" $@ "
9
+ fi
10
+ git log --color --graph --abbrev-commit \
11
+ --pretty=format:' %Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<author:%an == commitor:%cn>%Creset' \
12
+ $params
13
+ }
14
+ hist " $@ "
Original file line number Diff line number Diff line change 1
1
#! /bin/sh
2
2
3
3
last () {
4
- branch=` git symbolic-ref refs/remotes/origin/HEAD`
5
- git log --pretty=%H $branch | head -1 | xargs git checkout
4
+ REMOTE=$( git remote)
5
+ branch=${1:- $(git symbolic-ref " refs/remotes/$REMOTE /HEAD" )}
6
+ git log -n 1 --pretty=%H " $branch " | git checkout
6
7
}
7
- last " $@ "
8
+ last " $@ "
Original file line number Diff line number Diff line change 1
1
#! /bin/sh
2
2
3
3
next () {
4
- branch=` git symbolic-ref refs/remotes/origin/HEAD`
4
+ REMOTE=$( git remote)
5
+ branch=$( git symbolic-ref " refs/remotes/$REMOTE /HEAD" )
5
6
if [ -z " $1 " ]; then
6
7
n=1
7
8
else
8
9
n=$1
9
10
fi
10
- git log --reverse --pretty=%H $branch | grep -A $n $( git rev-parse HEAD) | tail -1 | xargs git checkout
11
+ git log --reverse --pretty=%H " $branch " | grep -A $n $( git rev-parse HEAD) | tail -1 | xargs git checkout
11
12
}
12
13
next " $@ "
Original file line number Diff line number Diff line change
1
+ [alias]
2
+ hist = !"hist() { \
3
+ if test -z $1;then \
4
+ REMOTE=\"$(git remote)\"; \
5
+ params=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \
6
+ else \
7
+ params=\"$@\"; \
8
+ fi; \
9
+ git log \
10
+ --color \
11
+ --graph \
12
+ --abbrev-commit \
13
+ --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<author:%an == commitor:%cn>%Creset' \
14
+ $params; \
15
+ };hist"
16
+ swc-first = !"first() { \
17
+ REMOTE=\"$(git remote)\"; \
18
+ branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \
19
+ git switch --detach $(git log --reverse --pretty=%H \"$branch\" | head -1); \
20
+ };first"
21
+ swc-last = !"last(){ \
22
+ REMOTE=\"$(git remote)\"; \
23
+ branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \
24
+ git switch --detach $(git log -n 1 --pretty=%H \"$branch\"); \
25
+ };last"
26
+ swc-prev = !"prev(){ \
27
+ n=\"${1:-1}\"; \
28
+ git checkout HEAD~$n; \
29
+ };prev"
30
+ swc-next = !"next(){ \
31
+ REMOTE=\"$(git remote)\"; \
32
+ branch=\"$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")\"; \
33
+ n=\"${1:-1}\"; \
34
+ git switch --detach $(git log --reverse --pretty=%H \"$branch\" | grep -A $n $(git rev-parse HEAD) | tail -1); \
35
+ };next"
Original file line number Diff line number Diff line change 1
1
#! /bin/sh
2
2
3
3
prev () {
4
- branch=` git symbolic-ref refs/remotes/origin/HEAD`
5
4
if [ -z " $1 " ]; then
6
5
n=1
7
6
else
Original file line number Diff line number Diff line change 1
1
#! /bin/sh
2
- install -m 755 git-* /usr/local/bin
2
+ if test -f git-paging-alias.txt; then
3
+ git config --global --add include.path $( readlink -f git-paging-alias.txt)
4
+ else
5
+ install -m 755 git-* /usr/local/bin
6
+ fi
You can’t perform that action at this time.
0 commit comments