#5 Feature Request: `subbash/prompt`: checkout to ‘detached HEAD’

بسته‌شده
5 سال پیش باز شده توسط tukusejssirs · 3 دیدگاه

When chekout to an older commit, I think it would be nice to show where exactly I am checked out.

In this sense, when I am in the last commit of a branch (the ‘main’ commit of a branch), show only the branch name. Otherwise (when I checkout to older commit), I think of two possible solutions:

  • [branch_name]:[commit_short_hash]

  • [commit_short_hash]

I think the former is better for the readability and better orientation.

Currently, it shows (detached) which does not say anything about the commit.

See below how it is right now.

[ 8.42am]0 u0_a170@localhost: [romcal-es6]?1 ~/git/romcal/romcal-es6
$ git checkout ea5ddeadad08b82192e7093096249d6c63962650
Note: checking out 'ea5ddeadad08b82192e7093096249d6c63962650'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at ea5ddea issue #31: new country calendars for European countries

[ 8.43am]0 u0_a170@localhost: [(detached)]?1 ~/git/romcal/romcal-es6
$ git status
HEAD detached at ea5ddea
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        romcal.bundle.min.js

nothing added to commit but untracked files present (use "git add" to track)

[ 8.56am]0 u0_a170@localhost: [(detached)]?1 ~/git/romcal/romcal-es6
$ git branch
* (HEAD detached at ea5ddea)
  romcal-es6
When chekout to an older commit, I think it would be nice to show where exactly I am checked out. In this sense, when I am in the last commit of a branch (the ‘main’ commit of a branch), show only the branch name. Otherwise (when I checkout to older commit), I think of two possible solutions: - `[branch_name]:[commit_short_hash]` - `[commit_short_hash]` I think the former is better for the readability and better orientation. Currently, it shows `(detached)` which does not say anything about the commit. See below how it is right now. ```bash [ 8.42am]0 u0_a170@localhost: [romcal-es6]?1 ~/git/romcal/romcal-es6 $ git checkout ea5ddeadad08b82192e7093096249d6c63962650 Note: checking out 'ea5ddeadad08b82192e7093096249d6c63962650'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at ea5ddea issue #31: new country calendars for European countries [ 8.43am]0 u0_a170@localhost: [(detached)]?1 ~/git/romcal/romcal-es6 $ git status HEAD detached at ea5ddea Untracked files: (use "git add <file>..." to include in what will be committed) romcal.bundle.min.js nothing added to commit but untracked files present (use "git add" to track) [ 8.56am]0 u0_a170@localhost: [(detached)]?1 ~/git/romcal/romcal-es6 $ git branch * (HEAD detached at ea5ddea) romcal-es6 ```
demure نظر 5 سال پیش
مالک

Based on my understanding of being in a detached HEAD state, you are no longer in a branch when detached. (read this link for more.) If you do a git checkout -b test-branch abcdef12 then you can have a temp branch at that spot in history, but you are not in a detached head state.

So, my take on the best approach would be testing if branch.head (from --porcelain=2) matches "(detached)". If it does, then the branch.oid could be awked into the first eight digits, and the prompt could be something like:
dir_name [(d)] abcdef12 ->

What are your thoughts?

Based on my understanding of being in a `detached HEAD` state, you are no longer in a branch when detached. (read [this link](https://www.git-tower.com/learn/git/faq/detached-head-when-checkout-commit) for more.) If you do a `git checkout -b test-branch abcdef12` then you can have a temp branch at that spot in history, but you are not in a detached head state. So, my take on the best approach would be testing if `branch.head` (from `--porcelain=2`) matches "(detached)". If it does, then the `branch.oid` could be awked into the first eight digits, and the prompt could be something like: `dir_name [(d)] abcdef12 -> ` What are your thoughts?
tukusejssirs نظر 5 سال پیش
نویسنده

You’re right. I did know that I should create a new branch if I want to commit. However, I thought it is still connected to a branch.

On the display approach, as there is no branch and that the detached word is redundant, I think that instead of branch name, we could output the short hash. If you’d like it to have a visible difference between branch name and the hash, the square brackets ([]) could be replaced with round brackets (()), as in theory, one could name a branch with a hash-like name. Example:

[ 9.01am]0 u0_a170@localhost: (4078205) ~/git/dotfiles
$ git branch
* (HEAD detached at 4078205)
  master
You’re right. I did know that I should create a new branch if I want to commit. However, I _thought_ it is still connected to a branch. On the display approach, as there is no branch and that the `detached` word is redundant, I think that instead of branch name, we could output the short hash. If you’d like it to have a visible difference between branch name and the hash, the square brackets (`[]`) could be replaced with round brackets (`()`), as in theory, one could name a branch with a hash-like name. Example: ```bash [ 9.01am]0 u0_a170@localhost: (4078205) ~/git/dotfiles $ git branch * (HEAD detached at 4078205) master ```
demure نظر 5 سال پیش
مالک

This should now be added via commit 9fb5aca

This should now be added via commit 9fb5aca
demure 5 سال پیش بسته شد
برای پیوستن به گفتگو، وارد شودید.
بدون برچسب
bug
بدون نقطه عطف
بدون مسئول رسیدگی
2 مشارکت کننده
درحال بارگذاری...
لغو
ذخيره
هنوز محتوایی ایجاد نشده.