reattaching a detatched git head...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

reattaching a detatched git head...

Eliot Miranda-2
 
I'm stuck.  Don't know how I detached from the master.  I'm seeing this:

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 ed4a499... CogVM source as per VMMaker.oscog-eem.1958

I want to make this the new master, and then add a commit.  I'm stuck.  Git mavens, help please.

_,,,^..^,,,_
best, Eliot
Reply | Threaded
Open this post in threaded view
|

Re: reattaching a detatched git head...

johnmci
 
you need to make a branch

 git checkout -b Eliot    "that will make a branch at the current HEAD/commit point with any of your pending changing"  

stage & commit any work to the Eliot branch 

checkout Cog

merge Eliot        "To merge any changes into Cog"

push Cog back to github. 


On Tue, Oct 11, 2016 at 5:20 PM, Eliot Miranda <[hidden email]> wrote:
 
I'm stuck.  Don't know how I detached from the master.  I'm seeing this:

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 ed4a499... CogVM source as per VMMaker.oscog-eem.1958

I want to make this the new master, and then add a commit.  I'm stuck.  Git mavens, help please.

_,,,^..^,,,_
best, Eliot




--
===========================================================================
John M. McIntosh. Corporate Smalltalk Consulting Ltd https://www.linkedin.com/in/smalltalk
===========================================================================
Reply | Threaded
Open this post in threaded view
|

Re: reattaching a detatched git head...

Jakob Reschke-2
In reply to this post by Eliot Miranda-2
 

To determine the correct/best course of action, it might also help to see what happened or where your detached head actaully is (oh, the plethora of possible puns!). You can look at the history graph with `gitk --all` (it should come with git). You can also create, checkout and move branches around there or do things like cherry picking, maybe even merging, not sure atm.


Am 12.10.2016 03:21 schrieb "John McIntosh" <[hidden email]>:
 
Reply | Threaded
Open this post in threaded view
|

Re: reattaching a detatched git head...

Nicolas Passerini
 
If you do 

git reset --soft refs/heads/master

That will leave you in a state in which
- your current branch is master again
- you still have all your files.

There you can commit onto master.

------------------------
Another posibility (maybe tidier) is to do that in another branch, so first:

git co -b new-branch-name
git add ...
git commit ...

and after you have everything working you go back and update master:
git co master
git merge new-branch-name



On Wed, Oct 12, 2016 at 10:40 AM, Jakob Reschke <[hidden email]> wrote:
 

To determine the correct/best course of action, it might also help to see what happened or where your detached head actaully is (oh, the plethora of possible puns!). You can look at the history graph with `gitk --all` (it should come with git). You can also create, checkout and move branches around there or do things like cherry picking, maybe even merging, not sure atm.


Am 12.10.2016 03:21 schrieb "John McIntosh" <[hidden email]>:
 


Reply | Threaded
Open this post in threaded view
|

Re: reattaching a detatched git head...

Nicolas Passerini
 
 But also I think it might be a good idea to try to answer Jakob's question first:

How did you arrive to a detached head status?

Because there could be other courses of action depending on that answer.
 
On Wed, Oct 12, 2016 at 10:40 AM, Jakob Reschke <[hidden email]> wrote:
 

To determine the correct/best course of action, it might also help to see what happened or where your detached head actaully is (oh, the plethora of possible puns!). You can look at the history graph with `gitk --all` (it should come with git). You can also create, checkout and move branches around there or do things like cherry picking, maybe even merging, not sure atm.


Am 12.10.2016 03:21 schrieb "John McIntosh" <[hidden email]>:
 



Reply | Threaded
Open this post in threaded view
|

Re: reattaching a detatched git head...

Ben Coman
In reply to this post by Eliot Miranda-2
 
On Wed, Oct 12, 2016 at 8:20 AM, Eliot Miranda <[hidden email]> wrote:
>
> I'm stuck.  Don't know how I detached from the master.

Maybe a good opportunity to peek under the hood to understand how it
may have happened.   I'm freshly enlightened from reading around the
subject past couple of hours and I picked a few of the best
articles...

A programming analogy providing an interesting alternative to most articles...
  http://gitolite.com/detached-head.html

coupled with a visual presentation...
  http://marklodato.github.io/visual-git-guide/index-en.html#detached

and bringing it together (with a comparison to Mercurial)...
  http://ideasintosoftware.com/git-detached-head-state-for-dummies/


> I'm seeing this:
>
> 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 ed4a499... CogVM source as per VMMaker.oscog-eem.1958
>
> I want to make this the new master, and then add a commit.  I'm stuck.  Git mavens, help please.

At  https://github.com/OpenSmalltalk/opensmalltalk-vm/network
I see that ed4a499 at this moment is a couple of commits back from the
tip of the Cog branch around the 12 Oct
but no merges after that, so without more background info I'll assume
for discussion a hypothetical scenario where you wanted to throw away
some local commits and in svn you would use 'checkout' (??) so you
used something like 'git checkout HEAD~1' instead of  'git reset
HEAD~1' to move to branch to a previous commit??   The difference is
demostrated here... (use left/right arrow keys to navigate)
  http://gitolite.com/gcs.html#(45)

John's example seems a common way to deal with a detached HEAD. Since
the commit was given to you actually could probably do...
  $ git checkout Cog
  $ git merge ed4a499
except that wouldn't help the hypothetical scenario above if the Cog
branch had moved forward with commits you wanted to kill.  If these
were only local changes, then 'reset' is probably what you need, but
if the commits had already been made public, 'revert' may be more
appropriate.
  https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting/file-level-operations

cheers -ben
Reply | Threaded
Open this post in threaded view
|

Re: reattaching a detatched git head...

philippeback
 
git checkout -b eliot_path_leading_to_this_point

From there, well, add, commit

Then checkout the dev or master branch and just rebase or merge the eliot_path_leading_to_this_point one in it.

Phil

On Wed, Oct 12, 2016 at 7:22 PM, Ben Coman <[hidden email]> wrote:

On Wed, Oct 12, 2016 at 8:20 AM, Eliot Miranda <[hidden email]> wrote:
>
> I'm stuck.  Don't know how I detached from the master.

Maybe a good opportunity to peek under the hood to understand how it
may have happened.   I'm freshly enlightened from reading around the
subject past couple of hours and I picked a few of the best
articles...

A programming analogy providing an interesting alternative to most articles...
  http://gitolite.com/detached-head.html

coupled with a visual presentation...
  http://marklodato.github.io/visual-git-guide/index-en.html#detached

and bringing it together (with a comparison to Mercurial)...
  http://ideasintosoftware.com/git-detached-head-state-for-dummies/


> I'm seeing this:
>
> 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 ed4a499... CogVM source as per VMMaker.oscog-eem.1958
>
> I want to make this the new master, and then add a commit.  I'm stuck.  Git mavens, help please.

At  https://github.com/OpenSmalltalk/opensmalltalk-vm/network
I see that ed4a499 at this moment is a couple of commits back from the
tip of the Cog branch around the 12 Oct
but no merges after that, so without more background info I'll assume
for discussion a hypothetical scenario where you wanted to throw away
some local commits and in svn you would use 'checkout' (??) so you
used something like 'git checkout HEAD~1' instead of  'git reset
HEAD~1' to move to branch to a previous commit??   The difference is
demostrated here... (use left/right arrow keys to navigate)
  http://gitolite.com/gcs.html#(45)

John's example seems a common way to deal with a detached HEAD. Since
the commit was given to you actually could probably do...
  $ git checkout Cog
  $ git merge ed4a499
except that wouldn't help the hypothetical scenario above if the Cog
branch had moved forward with commits you wanted to kill.  If these
were only local changes, then 'reset' is probably what you need, but
if the commits had already been made public, 'revert' may be more
appropriate.
  https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting/file-level-operations

cheers -ben


Reply | Threaded
Open this post in threaded view
|

Re: reattaching a detatched git head...

philippeback
In reply to this post by Ben Coman
 
This may help grokking it.

https://git-scm.com/book/en/v2/Git-Branching-Rebasing

And do yourself a favor, install tig.



Linux

apt-get install tig
yum install tig

OSX

brew install tig

useful commands:

tig status

or any git command piped into it.

e.g.
git log | tig

tig log would work too.

Can't live without this thing on the command line.


Other useful Git beasts:

git gui
gitk






On Wed, Oct 12, 2016 at 7:22 PM, Ben Coman <[hidden email]> wrote:

On Wed, Oct 12, 2016 at 8:20 AM, Eliot Miranda <[hidden email]> wrote:
>
> I'm stuck.  Don't know how I detached from the master.

Maybe a good opportunity to peek under the hood to understand how it
may have happened.   I'm freshly enlightened from reading around the
subject past couple of hours and I picked a few of the best
articles...

A programming analogy providing an interesting alternative to most articles...
  http://gitolite.com/detached-head.html

coupled with a visual presentation...
  http://marklodato.github.io/visual-git-guide/index-en.html#detached

and bringing it together (with a comparison to Mercurial)...
  http://ideasintosoftware.com/git-detached-head-state-for-dummies/


> I'm seeing this:
>
> 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 ed4a499... CogVM source as per VMMaker.oscog-eem.1958
>
> I want to make this the new master, and then add a commit.  I'm stuck.  Git mavens, help please.

At  https://github.com/OpenSmalltalk/opensmalltalk-vm/network
I see that ed4a499 at this moment is a couple of commits back from the
tip of the Cog branch around the 12 Oct
but no merges after that, so without more background info I'll assume
for discussion a hypothetical scenario where you wanted to throw away
some local commits and in svn you would use 'checkout' (??) so you
used something like 'git checkout HEAD~1' instead of  'git reset
HEAD~1' to move to branch to a previous commit??   The difference is
demostrated here... (use left/right arrow keys to navigate)
  http://gitolite.com/gcs.html#(45)

John's example seems a common way to deal with a detached HEAD. Since
the commit was given to you actually could probably do...
  $ git checkout Cog
  $ git merge ed4a499
except that wouldn't help the hypothetical scenario above if the Cog
branch had moved forward with commits you wanted to kill.  If these
were only local changes, then 'reset' is probably what you need, but
if the commits had already been made public, 'revert' may be more
appropriate.
  https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting/file-level-operations

cheers -ben