Skip to main content
Remove unnecessary spaces
Source Link
Benjamin Loison
  • 5.5k
  • 4
  • 18
  • 37

Git has commands for every action imaginable, but it needs extensive knowledge to get things right and because of that it is counter-intuitive at best...

What you did before:

  • Changed a file and used git add ., or git add <file>.

What you want:

  • Remove the file from the index, but keep it versioned and left with uncommitted changes in working copy:

     git reset HEAD <file>
    
  • Reset the file to the last state from HEAD, undoing changes and removing them from the index:

     # Think `svn revert <file>` IIRC.
     git reset HEAD <file>
     git checkout <file>
    
     # If you have a `<branch>` named like `<file>`, use:
     git checkout -- <file>
    

    This is needed since git reset --hard HEAD won't work with single files.

  • Remove <file> from index and versioning, keeping the un-versioned file with changes in working copy:

     git rm --cached <file>
    
  • Remove <file> from working copy and versioning completely:

     git rm <file>
    

Git has commands for every action imaginable, but it needs extensive knowledge to get things right and because of that it is counter-intuitive at best...

What you did before:

  • Changed a file and used git add ., or git add <file>.

What you want:

  • Remove the file from the index, but keep it versioned and left with uncommitted changes in working copy:

     git reset HEAD <file>
    
  • Reset the file to the last state from HEAD, undoing changes and removing them from the index:

     # Think `svn revert <file>` IIRC.
     git reset HEAD <file>
     git checkout <file>
    
     # If you have a `<branch>` named like `<file>`, use:
     git checkout -- <file>
    

    This is needed since git reset --hard HEAD won't work with single files.

  • Remove <file> from index and versioning, keeping the un-versioned file with changes in working copy:

     git rm --cached <file>
    
  • Remove <file> from working copy and versioning completely:

     git rm <file>
    

Git has commands for every action imaginable, but it needs extensive knowledge to get things right and because of that it is counter-intuitive at best...

What you did before:

  • Changed a file and used git add ., or git add <file>.

What you want:

  • Remove the file from the index, but keep it versioned and left with uncommitted changes in working copy:

    git reset HEAD <file>
    
  • Reset the file to the last state from HEAD, undoing changes and removing them from the index:

    # Think `svn revert <file>` IIRC.
    git reset HEAD <file>
    git checkout <file>
    
    # If you have a `<branch>` named like `<file>`, use:
    git checkout -- <file>
    

    This is needed since git reset --hard HEAD won't work with single files.

  • Remove <file> from index and versioning, keeping the un-versioned file with changes in working copy:

    git rm --cached <file>
    
  • Remove <file> from working copy and versioning completely:

    git rm <file>
    
edited body
Source Link
sjas
  • 19.2k
  • 14
  • 92
  • 94

Git has commands for every action imaginable, but it needs extensive knowledge to get things right and because of that it is counter-intuitive at best...

What you did before:

  • Changed a file and used git add ., or git add <file>.

What you want:

  • Remove the file from the index, but keep it versioned and left with uncommitted changes in working copy:

     git reset headHEAD <file>
    
  • Reset the file to the last state from HEAD, undoing changes and removing them from the index:

     # Think `svn revert <file>` IIRC.
     git reset HEAD <file>
     git checkout <file>
    
     # If you have a `<branch>` named like `<file>`, use:
     git checkout -- <file>
    

    This is needed since git reset --hard HEAD won't work with single files.

  • Remove <file> from index and versioning, keeping the un-versioned file with changes in working copy:

     git rm --cached <file>
    
  • Remove <file> from working copy and versioning completely:

     git rm <file>
    

Git has commands for every action imaginable, but it needs extensive knowledge to get things right and because of that it is counter-intuitive at best...

What you did before:

  • Changed a file and used git add ., or git add <file>.

What you want:

  • Remove the file from the index, but keep it versioned and left with uncommitted changes in working copy:

     git reset head <file>
    
  • Reset the file to the last state from HEAD, undoing changes and removing them from the index:

     # Think `svn revert <file>` IIRC.
     git reset HEAD <file>
     git checkout <file>
    
     # If you have a `<branch>` named like `<file>`, use:
     git checkout -- <file>
    

    This is needed since git reset --hard HEAD won't work with single files.

  • Remove <file> from index and versioning, keeping the un-versioned file with changes in working copy:

     git rm --cached <file>
    
  • Remove <file> from working copy and versioning completely:

     git rm <file>
    

Git has commands for every action imaginable, but it needs extensive knowledge to get things right and because of that it is counter-intuitive at best...

What you did before:

  • Changed a file and used git add ., or git add <file>.

What you want:

  • Remove the file from the index, but keep it versioned and left with uncommitted changes in working copy:

     git reset HEAD <file>
    
  • Reset the file to the last state from HEAD, undoing changes and removing them from the index:

     # Think `svn revert <file>` IIRC.
     git reset HEAD <file>
     git checkout <file>
    
     # If you have a `<branch>` named like `<file>`, use:
     git checkout -- <file>
    

    This is needed since git reset --hard HEAD won't work with single files.

  • Remove <file> from index and versioning, keeping the un-versioned file with changes in working copy:

     git rm --cached <file>
    
  • Remove <file> from working copy and versioning completely:

     git rm <file>
    
Active reading.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132

Git has commands for every action imaginable, but it needs extensive knowledge to get things right and because of that it is counter-intuitive at best...

What you did before:

  • Changed a file and used git add ., or git add <file>.

What you want:

  • Remove the file from the index, but keep it versioned and left with uncommitted changes in working copy:

     git reset head <file>
    
  • Reset the file to the last state from HEAD, undoing changes and removing them from the index:

     # Think `svn revert <file>` IIRC.
     git reset HEAD <file>
     git checkout <file>
    
     # If you have a `<branch>` named like `<file>`, use:
     git checkout -- <file>
    

    This is needed since git reset --hard HEAD won't work with single files.

  • Remove <file> from index and versioning, keeping the un-versioned file with changes in working copy:

     git rm --cached <file>
    
  • Remove <file> from working copy and versioning completely:

     git rm <file>
    

Git has commands for every action imaginable, but needs extensive knowledge to get things right and because of that it is counter-intuitive at best...

What you did before:

  • Changed a file and used git add ., or git add <file>.

What you want:

  • Remove the file from the index, but keep it versioned and left with uncommitted changes in working copy:

     git reset head <file>
    
  • Reset the file to the last state from HEAD, undoing changes and removing them from the index:

     # Think `svn revert <file>` IIRC.
     git reset HEAD <file>
     git checkout <file>
    
     # If you have a `<branch>` named like `<file>`, use:
     git checkout -- <file>
    

    This is needed since git reset --hard HEAD won't work with single files.

  • Remove <file> from index and versioning, keeping the un-versioned file with changes in working copy:

     git rm --cached <file>
    
  • Remove <file> from working copy and versioning completely:

     git rm <file>
    

Git has commands for every action imaginable, but it needs extensive knowledge to get things right and because of that it is counter-intuitive at best...

What you did before:

  • Changed a file and used git add ., or git add <file>.

What you want:

  • Remove the file from the index, but keep it versioned and left with uncommitted changes in working copy:

     git reset head <file>
    
  • Reset the file to the last state from HEAD, undoing changes and removing them from the index:

     # Think `svn revert <file>` IIRC.
     git reset HEAD <file>
     git checkout <file>
    
     # If you have a `<branch>` named like `<file>`, use:
     git checkout -- <file>
    

    This is needed since git reset --hard HEAD won't work with single files.

  • Remove <file> from index and versioning, keeping the un-versioned file with changes in working copy:

     git rm --cached <file>
    
  • Remove <file> from working copy and versioning completely:

     git rm <file>
    
formatting fix
Source Link
Mark Amery
  • 150.3k
  • 87
  • 415
  • 465
Loading
Cleaned up formatting, now it's a little easier to read.
Source Link
user456814
user456814
Loading
added 2 characters in body
Source Link
sjas
  • 19.2k
  • 14
  • 92
  • 94
Loading
added 56 characters in body
Source Link
sjas
  • 19.2k
  • 14
  • 92
  • 94
Loading
edited body
Source Link
sjas
  • 19.2k
  • 14
  • 92
  • 94
Loading
Source Link
sjas
  • 19.2k
  • 14
  • 92
  • 94
Loading