Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cof, col, cop and con alias #116

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions doc/git-cof/README.md
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions doc/git-cof/index.md
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions doc/git-col/README.md
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions doc/git-col/index.md
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions doc/git-con/README.md
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions doc/git-con/index.md
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions doc/git-cop/README.md
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions doc/git-cop/index.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Loading