Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Now as I'm making commits to my project it shows the SHA-1 on the command line as the working branch (instead of master)</em></p> <p>This probably means you have a “detached HEAD”. A detached HEAD points directly to a commit instead of pointing to a branch (which then points to a commit). A detached head is like an unnamed branch.</p> <p>This state was caused by your <code>git checkout HEAD^</code> command as <code>HEAD^</code> refers to a commit, not to a branch name. You probably wanted to do <code>git reset --hard HEAD^</code>—<strong>while <em>master</em> was still the active branch</strong>—to drop the most recent commit from <em>master</em> (it would still exist on disk and be reachable through the reflog until its entry in the reflog expired).</p> <p><em>How can I point HEAD to the latest commit I'm working from?</em></p> <p><code>HEAD</code> is always the commit from which you are working, whether it is detached or not.</p> <p>If you mean “How can I point <em>master</em> to the latest commit I'm working from?”, then that is the same as asking “How can I get <em>master</em> to point to <code>HEAD</code>?”. The answer is</p> <pre><code>git branch -f master HEAD </code></pre> <p>(actually, you can leave off <code>HEAD</code>, since it is the default). This forcibly resets <em>master</em> to the commit currently at <code>HEAD</code>. Any commits on <em>master</em> that are not reachable via another branch or the current <code>HEAD</code> will henceforth only be reachable via the reflog and will eventually be garbage collected (this throws away, from <em>master</em>, anything in <em>master</em> that is not in <code>HEAD</code>). You also probably want to reattach your <code>HEAD</code> to this updated master after this.</p> <pre><code>git checkout master </code></pre> <p>Instead of the two commands above, you could reattach <code>HEAD</code> first, then reset <em>master</em> with these two consecutive commands:</p> <pre><code>git checkout master # reattach, commit at HEAD is now the unwanted commit git reset --hard HEAD@{1} # reset master to the commit at HEAD before the prior command </code></pre> <p>The <code>HEAD@{1}</code> notation is used to access entries in the reflog. This example just means “the previous <code>HEAD</code>” (i.e. “the commit at <code>HEAD</code> before the most recent operation that affected <code>HEAD</code>”).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload