Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two ways of handling this. Which is easier depends on your situation</p> <p><strong>Reset</strong></p> <p>If the commit you want to get rid of was the last commit, and you have not done any additional work you can simply use <code>git-reset</code></p> <pre><code>git reset HEAD^ </code></pre> <p>Takes your branch back to the commit just before your current HEAD. However, it doesn't actually change the files in your working tree. As a result, the changes that were in that commit show up as modified - its like an 'uncommit' command. In fact, I have an alias to do just that.</p> <pre><code>git config --global alias.uncommit 'reset HEAD^' </code></pre> <p>Then you can just used <code>git uncommit</code> in the future to back up one commit.</p> <p><strong>Squashing</strong></p> <p>Squashing a commit means combining two or more commits into one. I do this quite often. In your case you have a half done feature commited, and then you would finish it off and commit again with the proper, permanent commit message.</p> <pre><code>git rebase -i &lt;ref&gt; </code></pre> <p>I say above because I want to make it clear this could be any number of commits back. Run <code>git log</code> and find the commit you want to get rid of, copy its SHA1 and use it in place of <code>&lt;ref&gt;</code>. Git will take you into interactive rebase mode. It will show all the commits between your current state and whatever you put in place of <code>&lt;ref&gt;</code>. So if <code>&lt;ref&gt;</code> is 10 commits ago, it will show you all 10 commits.</p> <p>In front of each commit, it will have the word <code>pick</code>. Find the commit you want to get rid of and change it from <code>pick</code> to <code>fixup</code> or <code>squash</code>. Using <code>fixup</code> simply discards that commits message and merges the changes into its immediate predecessor in the list. The <code>squash</code> keyword does the same thing, but allows you to edit the commit message of the newly combined commit.</p> <p>Note that the commits will be re-committed in the order they show up on the list when you exit the editor. So if you made a temporary commit, then did other work on the same branch, and completed the feature in a later commit, then using rebase would allow you to re-sort the commits and squash them.</p> <p><strong>WARNING:</strong></p> <p><em>Rebasing modifies history - DONT do this to any commits you have already shared with other developers.</em></p> <p><strong>Stashing</strong></p> <p>In the future, to avoid this problem consider using <code>git stash</code> to temporarily store uncommitted work.</p> <pre><code>git stash save 'some message' </code></pre> <p>This will store your current changes off to the side in your stash list. Above is the most explicit version of the stash command, allowing for a comment to describe what you are stashing. You can also simply run <code>git stash</code> and nothing else, but no message will be stored. </p> <p>You can browse your stash list with...</p> <pre><code>git stash list </code></pre> <p>This will show you all your stashes, what branches they were done on, and the message and at the beginning of each line, and identifier for that stash which looks like this <code>stash@{#}</code> where # is its position in the array of stashes.</p> <p>To restore a stash (which can be done on any branch, regardless of where the stash was originally created) you simply run...</p> <pre><code>git stash apply stash@{#} </code></pre> <p>Again, there # is the position in the array of stashes. If the stash you want to restore is in the <code>0</code> position - that is, if it was the most recent stash. Then you can just run the command without specifying the stash position, git will assume you mean the last one: <code>git stash apply</code>.</p> <p>So, for example, if I find myself working on the wrong branch - I may run the following sequence of commands.</p> <pre><code>git stash git checkout &lt;correct_branch&gt; git stash apply </code></pre> <p>In your case you moved around branches a bit more, but the same idea still applies.</p> <p>Hope this helps.</p>
    singulars
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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