-
Notifications
You must be signed in to change notification settings - Fork 335
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: MinsonLee <lms.minsonlee@gmail.com>
* `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 <lms.minsonlee@gmail.com>
|
@@ -156,11 +156,109 @@ | |||
|
|||
# checkout - update the working tree to match a branch or paths. [same as "o" for "out"] | |||
co = checkout | |||
cog = checkout -guess |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-guess
with a single dash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your reply.
I saw there is an alias for cog
in readme.md, but I didn't find it in gitalias.txt.
I re-read the git documentation about git-checkout and found a sentence :
--guess is the default behavior. Use --no-guess to disable it.
I think it would be better to remove the cog
alias description in README.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only concern was a single dash. --guess
must be with double dashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should be --guess
# git cof foo | ||
# | ||
cof = !"f() { \ | ||
REMOTE=\"$(git remote)\"; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the repository has multiple remotes? I often have 2 or 3 — gh
for GitHub, origin
for my own clean copy, and web
to publish at my own hosting.
# | ||
cof = !"f() { \ | ||
REMOTE=\"$(git remote)\"; \ | ||
branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if you get one remote repo git symbolic-ref
could fail:
$ git symbolic-ref refs/remotes/gh/HEAD
fatal: ref refs/remotes/gh/HEAD is not a symbolic ref
# | ||
cof = !"f() { \ | ||
REMOTE=\"$(git remote)\"; \ | ||
branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if there is a parameter you can skip these 2 commands thus making these aliases faster.
# | ||
cof = !"f() { \ | ||
REMOTE=\"$(git remote)\"; \ | ||
branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if there are no parameters why work with remotes at all? In detached HEAD state remote HEAD
could be completely different from the current HEAD
, it's hardly a way to get the current branch. There is no reliable way to get the current branch in detached HEAD state. If my current branch is development
and current commit is development~10
, but the remote HEAD
is refs/remotes/origin/master
then what?
IMO the best course of actions would be to get the current branch from the HEAD
and in case of detached HEAD fail and force user to provide branch name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or may be guess with git branch --contains HEAD
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git for-each-ref --contains HEAD --count=1 --format="%(refname)" refs/heads/
cong = checkout --no-guess | ||
|
||
# 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps IWBN to explain that "first commit" means the very first, initial commit of the current tree, not the commit from which the current branch was forked.
May be split these aliases into smaller parts? 1. Get the current branch, single alias. 2. Get the next/prev/1st/last commit. 3. Checkout to the next/prev/1st/last commit. |
When |
Great ideas and PR, thank you. Great comments @phdru. Here's what I see in this PR... there's an implementation request here that you both are suggesting. How does a user query for a specific commit? This is a big topic that entangles many developers. What could this commit look like if there's an entirely new top-level one-letter gitalias that queries for a commit hash? Then you could do query by position (first, prev, etc), query by metadata (author, date, etc.), query by content (text, bisect), etc. |
@phdru Thank you for these great suggestions! I'll try to fix it and resolve it when I have some free time |
No description provided.