Skip to content

Commit 7bb991c

Browse files
authored
Merge pull request #4 from MinsonLee/master
Fix multi remote error、add `git hist` and update the install.sh
2 parents b35a6b8 + 6d50944 commit 7bb991c

File tree

8 files changed

+85
-10
lines changed

8 files changed

+85
-10
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
Treat git log as a book, exec `git next` or `git prev` to checkout the next or the previous commit.
44

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 历史节点
625

726
请查看博客文章 [阅读开源代码小技巧](https://hutusi.com/git-paging) 获得更多使用帮助。
27+

git-first

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/sh
22

33
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
67
}
78
first "$@"

git-hist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 "$@"

git-last

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/sh
22

33
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
67
}
7-
last "$@"
8+
last "$@"

git-next

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/bin/sh
22

33
next() {
4-
branch=`git symbolic-ref refs/remotes/origin/HEAD`
4+
REMOTE=$(git remote)
5+
branch=$(git symbolic-ref "refs/remotes/$REMOTE/HEAD")
56
if [ -z "$1" ]; then
67
n=1
78
else
89
n=$1
910
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
1112
}
1213
next "$@"

git-paging-alias.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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"

git-prev

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/sh
22

33
prev() {
4-
branch=`git symbolic-ref refs/remotes/origin/HEAD`
54
if [ -z "$1" ]; then
65
n=1
76
else

install.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
#!/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

0 commit comments

Comments
 (0)