From 9f7b549d1b46722921a82a7d46e92eba18675364 Mon Sep 17 00:00:00 2001 From: MinsonLee Date: Sat, 18 Jan 2025 11:35:02 +0800 Subject: [PATCH 1/2] feat: Add `git cog` alias for `git checkout --guess` Signed-off-by: MinsonLee --- gitalias.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/gitalias.txt b/gitalias.txt index 6c29072..9cd7311 100644 --- a/gitalias.txt +++ b/gitalias.txt @@ -156,6 +156,7 @@ # checkout - update the working tree to match a branch or paths. [same as "o" for "out"] co = checkout + cog = checkout -guess cong = checkout --no-guess # create a new branch from the current working tree, and switch to it From c980ec0ed383d5bf044a90f16009ec5dc0181f9d Mon Sep 17 00:00:00 2001 From: MinsonLee Date: Sat, 18 Jan 2025 15:19:39 +0800 Subject: [PATCH 2/2] feat: Add cof, col, cop and con alias * `git cof` - switch to a branch's first commit hash * `git col` - switch to a branch's last commit hash * `git cop` - switch to the previous (or previous N) commit hash * `git con` - switch to the next (or next N) commit Signed-off-by: MinsonLee --- README.md | 8 ++++ doc/git-cof/README.md | 42 +++++++++++++++++++ doc/git-cof/index.md | 42 +++++++++++++++++++ doc/git-col/README.md | 42 +++++++++++++++++++ doc/git-col/index.md | 42 +++++++++++++++++++ doc/git-con/README.md | 43 +++++++++++++++++++ doc/git-con/index.md | 43 +++++++++++++++++++ doc/git-cop/README.md | 35 ++++++++++++++++ doc/git-cop/index.md | 35 ++++++++++++++++ doc/index.md | 4 ++ gitalias.txt | 97 +++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 433 insertions(+) create mode 100644 doc/git-cof/README.md create mode 100644 doc/git-cof/index.md create mode 100644 doc/git-col/README.md create mode 100644 doc/git-col/index.md create mode 100644 doc/git-con/README.md create mode 100644 doc/git-con/index.md create mode 100644 doc/git-cop/README.md create mode 100644 doc/git-cop/index.md diff --git a/README.md b/README.md index c4f5049..aac74e4 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,10 @@ git checkout: * [git cog](doc/git-cog/) = checkout --guess * [git cong](doc/git-cong/) = checkout --no-guess * [git cob](doc/git-cob/) = checkout -b + * [git cof](doc/git-cof/) - Switch to a branch's first commit hash + * [git col](doc/git-col/) = Switch to a branch's last commit hash + * [git cop](doc/git-cop/) = Switch to the previous (or previous N) commit hash + * [git con](doc/git-con/) = Switch to the next (or next N) commit hash git cherry-pick: @@ -420,6 +424,10 @@ Use graphviz: * [git cog](doc/git-cog/) - Checkout with guessing * [git cong](doc/git-cong/) - Checkout with no guessing * [git cob](doc/git-cob/) - Create a new branch from the current working tree, and switch to it + * [git cof](doc/git-cof/) - Switch to a branch's first commit hash + * [git col](doc/git-col/) = Switch to a branch's last commit hash + * [git cop](doc/git-cop/) = Switch to the previous (or previous N) commit hash + * [git con](doc/git-con/) = Switch to the next (or next N) commit hash * [git commit-is-merge](doc/git-commit-is-merge/) - Is the commit a merge commit? If yes exit 0, else exit 1 * [git commit-message-key-lines](doc/git-commit-message-key-lines/) - Show the commit's keyword-marker lines * [git commit-parents](doc/git-commit-parents/) - Show the commit's parents diff --git a/doc/git-cof/README.md b/doc/git-cof/README.md new file mode 100644 index 0000000..5051ff4 --- /dev/null +++ b/doc/git-cof/README.md @@ -0,0 +1,42 @@ +# git cof + +## Switch to a branch's first commit hash + +Git alias: + +```git +cof = !"f() { \ + REMOTE=\"$(git remote)\"; \ + branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ + git checkout $(git log --reverse --pretty=%H \"$branch\" | head -1); \ +};f" +``` + +Syntax: + +```shell +git cof [branch name] +``` + +Options: + + * branch name: default is the current branch name. + +Example: switch to the current branch's first commit hash: + +```shell +git cof +``` + +Example: switch to the "foo" branch's first commit hash: + +```shell +git cof foo +``` + +Compare: + +* [git cof](../git-cof): switch to a branch's first commit hash +* [git col](../git-col): switch to a branch's last commit hash +* [git cop](../git-cop): switch to the previous (or previous n) commit hash +* [git con](../git-con): switch to the next (or next n) commit \ No newline at end of file diff --git a/doc/git-cof/index.md b/doc/git-cof/index.md new file mode 100644 index 0000000..687a3a2 --- /dev/null +++ b/doc/git-cof/index.md @@ -0,0 +1,42 @@ +# git cof + +## Switch to a branch's first commit hash + +Git alias: + +```git +cof = !"f() { \ + REMOTE=\"$(git remote)\"; \ + branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ + git checkout $(git log --reverse --pretty=%H \"$branch\" | head -1); \ +};f" +``` + +Syntax: + +```shell +git cof [branch name] +``` + +Options: + + * branch name: default is the current branch name. + +Example: switch to the current branch's first commit hash: + +```shell +git cof +``` + +Example: switch to the "foo" branch's first commit hash: + +```shell +git cof foo +``` + +Compare: + +* [git cof](../git-cof): switch to a branch's first commit hash +* [git col](../git-col): switch to a branch's last commit hash +* [git cop](../git-cop): switch to the previous (or previous n) commit hash +* [git con](../git-con): switch to the next (or next n) commit diff --git a/doc/git-col/README.md b/doc/git-col/README.md new file mode 100644 index 0000000..df60355 --- /dev/null +++ b/doc/git-col/README.md @@ -0,0 +1,42 @@ +# git col + +## Switch to a branch's last commit hash + +Git alias: + +```git +col = !"f(){ \ + REMOTE=\"$(git remote)\"; \ + branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ + git checkout $(git log -n 1 --pretty=%H \"$branch\"); \ +};f" +``` + +Syntax: + +```shell +git col [branch name] +``` + +Options: + + * branch name: default is the current branch name. + +Example: switch to the current branch's last commit hash: + +```shell +git col +``` + +Example: switch to the "foo" branch's last commit hash: + +```shell +git cof foo +``` + +Compare: + +* [git cof](../git-cof): switch to a branch's first commit hash +* [git col](../git-col): switch to a branch's last commit hash +* [git cop](../git-cop): switch to the previous (or previous n) commit hash +* [git con](../git-con): switch to the next (or next n) commit \ No newline at end of file diff --git a/doc/git-col/index.md b/doc/git-col/index.md new file mode 100644 index 0000000..df60355 --- /dev/null +++ b/doc/git-col/index.md @@ -0,0 +1,42 @@ +# git col + +## Switch to a branch's last commit hash + +Git alias: + +```git +col = !"f(){ \ + REMOTE=\"$(git remote)\"; \ + branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ + git checkout $(git log -n 1 --pretty=%H \"$branch\"); \ +};f" +``` + +Syntax: + +```shell +git col [branch name] +``` + +Options: + + * branch name: default is the current branch name. + +Example: switch to the current branch's last commit hash: + +```shell +git col +``` + +Example: switch to the "foo" branch's last commit hash: + +```shell +git cof foo +``` + +Compare: + +* [git cof](../git-cof): switch to a branch's first commit hash +* [git col](../git-col): switch to a branch's last commit hash +* [git cop](../git-cop): switch to the previous (or previous n) commit hash +* [git con](../git-con): switch to the next (or next n) commit \ No newline at end of file diff --git a/doc/git-con/README.md b/doc/git-con/README.md new file mode 100644 index 0000000..7b4304e --- /dev/null +++ b/doc/git-con/README.md @@ -0,0 +1,43 @@ +# git branch-commit-first + +## Switch to the next (or next N) commit + +Git alias: + +```git +con = !"f(){ \ + REMOTE=\"$(git remote)\"; \ + branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ + n=\"${1:-1}\"; \ + git switch --detach $(git log --reverse --pretty=%H \"$branch\" | grep -A $n $(git rev-parse HEAD) | tail -1); \ +};f" +``` + +Syntax: + +```shell +git con [commit count] +``` + +Options: + + * commit count: default is 1 + +Example: Switch to the next commit of the current commit: + +```shell +git con +``` + +Example: Switch to the next 4th commit of the current commit: + +```shell +git con 3 +``` + +Compare: + +* [git cof](../git-cof): switch to a branch's first commit hash +* [git col](../git-col): switch to a branch's last commit hash +* [git cop](../git-cop): switch to the previous (or previous n) commit hash +* [git con](../git-con): switch to the next (or next n) commit \ No newline at end of file diff --git a/doc/git-con/index.md b/doc/git-con/index.md new file mode 100644 index 0000000..7b4304e --- /dev/null +++ b/doc/git-con/index.md @@ -0,0 +1,43 @@ +# git branch-commit-first + +## Switch to the next (or next N) commit + +Git alias: + +```git +con = !"f(){ \ + REMOTE=\"$(git remote)\"; \ + branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ + n=\"${1:-1}\"; \ + git switch --detach $(git log --reverse --pretty=%H \"$branch\" | grep -A $n $(git rev-parse HEAD) | tail -1); \ +};f" +``` + +Syntax: + +```shell +git con [commit count] +``` + +Options: + + * commit count: default is 1 + +Example: Switch to the next commit of the current commit: + +```shell +git con +``` + +Example: Switch to the next 4th commit of the current commit: + +```shell +git con 3 +``` + +Compare: + +* [git cof](../git-cof): switch to a branch's first commit hash +* [git col](../git-col): switch to a branch's last commit hash +* [git cop](../git-cop): switch to the previous (or previous n) commit hash +* [git con](../git-con): switch to the next (or next n) commit \ No newline at end of file diff --git a/doc/git-cop/README.md b/doc/git-cop/README.md new file mode 100644 index 0000000..9a92f0b --- /dev/null +++ b/doc/git-cop/README.md @@ -0,0 +1,35 @@ +# git cop + +## Switch to the previous (or previous N) commit hash + +Git alias: + +```git +cop = !"f(){ \ + n=\"${1:-1}\"; \ + git checkout HEAD~$n; \ +};f" +``` + +Syntax: + +```shell +git cop [commit count] +``` + +Options: + + * commit count: default is 1 + +Example: switch to the previous 4th commit hash of the current commit: + +```shell +git cop 4 +``` + +Compare: + +* [git cof](../git-cof): switch to a branch's first commit hash +* [git col](../git-col): switch to a branch's last commit hash +* [git cop](../git-cop): switch to the previous (or previous n) commit hash +* [git con](../git-con): switch to the next (or next n) commit diff --git a/doc/git-cop/index.md b/doc/git-cop/index.md new file mode 100644 index 0000000..214c2df --- /dev/null +++ b/doc/git-cop/index.md @@ -0,0 +1,35 @@ +# git cop + +## Switch to the previous (or previous N) commit hash + +Git alias: + +```git +cop = !"f(){ \ + n=\"${1:-1}\"; \ + git checkout HEAD~$n; \ +};f" +``` + +Syntax: + +```shell +git cop [commit count] +``` + +Options: + + * commit count: default is 1 + +Example: switch to the previous 4th commit hash of the current commit: + +```shell +git cop 4 +``` + +Compare: + +* [git cof](../git-cof): switch to a branch's first commit hash +* [git col](../git-col): switch to a branch's last commit hash +* [git cop](../git-cop): switch to the previous (or previous n) commit hash +* [git con](../git-con): switch to the next (or next n) commit \ No newline at end of file diff --git a/doc/index.md b/doc/index.md index cf0ae04..aa20c37 100644 --- a/doc/index.md +++ b/doc/index.md @@ -69,6 +69,10 @@ git checkout: * [git cog](git-cog/) = checkout --guess * [git cong](git-cong/) = checkout --no-guess * [git cob](git-cob/) = checkout -b + * [git cof](git-cof/) - Switch to a branch's first commit hash + * [git col](git-col/) = Switch to a branch's last commit hash + * [git cop](git-cop/) = Switch to the previous (or previous N) commit hash + * [git con](git-con/) = Switch to the next (or next N) commit hash git cherry-pick: diff --git a/gitalias.txt b/gitalias.txt index 9cd7311..e9fac67 100644 --- a/gitalias.txt +++ b/gitalias.txt @@ -162,6 +162,103 @@ # create a new branch from the current working tree, and switch to it cob = checkout -b + # cof - switch to a branch's first commit hash. + # + # Syntax: + # + # git cof [branch name] + # + # Options: + # + # * branch name: default is the current branch name. + # + # Example: switch to the current branch's first commit hash: + # + # git cof + # + # Example: switch to the "foo" branch's first commit hash: + # + # git cof foo + # + cof = !"f() { \ + REMOTE=\"$(git remote)\"; \ + branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ + git checkout $(git log --reverse --pretty=%H \"$branch\" | head -1); \ + };f" + + # col - switch to a branch's last commit hash. + # + # Syntax: + # + # git col [branch name] + # + # Options: + # + # * branch name: default is the current branch name. + # + # Example: switch to the current branch's last commit hash: + # + # git col + # + # Example: switch to the "foo" branch's last commit hash: + # + # git cof foo + # + col = !"f(){ \ + REMOTE=\"$(git remote)\"; \ + branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ + git checkout $(git log -n 1 --pretty=%H \"$branch\"); \ + };f" + + # cop - Switch to the previous (or previous N) commit hash of the current commit. + # + # Syntax: + # + # git cop [commit count] + # + # Options: + # + # * commit count: default is 1 + # + # Example: switch to the previous 1st commit hash of the current commit hash: + # + # git cop + # + # Example: switch to the commit hash that is previous 4th before the current commit: + # + # git cop 4 + # + cop = !"f(){ \ + n=\"${1:-1}\"; \ + git checkout HEAD~$n; \ + };f" + + # con - Switch to the next (or next N) commit of the current commit. + # + # Syntax: + # + # git con [commit count] + # + # Options: + # + # * commit count: default is 1 + # + # Example: switch to the previous commit hash of the current commit hash: + # + # git con + # + # Example: switch to the commit hash that is previous 4th before the current commit: + # + # git con 4 + # + con = !"f(){ \ + REMOTE=\"$(git remote)\"; \ + branch=\"$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")\"; \ + n=\"${1:-1}\"; \ + git checkout $(git log --reverse --pretty=%H \"$branch\" | grep -A $n $(git rev-parse HEAD) | tail -1); \ + };f" + + ### cherry-pick aliases ### # cherry-pick - apply the changes introduced by some existing commits; useful for moving small chunks of code between branches.