Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>I'm working on the master branch. I create file1 and commit.</p> </blockquote> <pre><code>date &gt;file1 git add file1 git commit -m 'added file1' </code></pre> <blockquote> <p>I create file2 and commit.</p> </blockquote> <pre><code>date &gt;file2 git add file2 git commit -m 'added file2' </code></pre> <blockquote> <p>Whoops. I may want to use file2, someday, but it's definitely not something that should be put in the master branch.</p> </blockquote> <p>Oops. Very simple. Make a new branch from where you are:</p> <pre><code>git checkout -b savingfile2 </code></pre> <p>This will make the file2 change the commit for <code>savingfile2</code>. Now go back and unwind one step on master</p> <pre><code>git checkout master git reset --hard HEAD~1 </code></pre> <p>At this point, the commits leading up to master will reflect the addition of file1, and the additional commit between master and savingfile2 will be the addition of file2 to that.</p> <p>If you make more changes to master, and then want to bring file2 back eventually, you'll want to rebase that side-branch onto the new master:</p> <pre><code>date &gt;file3 git add file3 git commit -m 'adding file3' date &gt;file4 git add file4 git commit -m 'adding file4' </code></pre> <p>And now we finally want file2:</p> <pre><code>git checkout savingfile2 git rebase master # might need to fix conflicts here git checkout master git merge savingfile2 # will be a fast-forward git branch -d savingfile2 # no need any more </code></pre> <p>That should do it.</p>
 

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