Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you've already pushed your commits to the origin, then the other solutions described here (using <code>git reset</code> or <code>git checkout</code>, followed by <code>git commit</code>) is your only sane option.</p> <p>However, <strong>if</strong> you haven't pushed your changes yet, <strong>and</strong> you want to remove all traces that the files were ever committed, an interactive rebase is a good option. Use the following command to rebase your last two commits:</p> <pre><code>git rebase --interactive HEAD~2 </code></pre> <p>An editor will open, showing your two commits. You want to edit the file to show the following, then save; particularly, you want to change <code>pick</code> in front of your first commit to <code>edit</code>:</p> <pre><code>edit b743075 Commit 1 pick 791962d Commit 2 </code></pre> <p>Git will then place us into a state where we can edit the first commit (without touching the second). It says you can amend the commit with <code>git commit --amend</code>, but we actually want to do a reset to the commit before head, and undo it entirely:</p> <pre><code>git reset HEAD^ </code></pre> <p>This will place the changes from Commit 1 back into your working tree. Then, <code>git add</code> only the files you want to keep, and re-commit them using <code>git commit</code>:</p> <pre><code>git add dir1/file1.cpp git add dir1/file1.h git commit -m "Commit 1" </code></pre> <p>Finally, do a hard reset to delete the files you don't want to keep from your working tree, and finish the rebase:</p> <pre><code>git reset --hard git rebase --continue </code></pre> <p>When the rebase is complete, your repository will have both commits, but no traces of the <code>file2.*</code> files.</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. 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.
    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