Skip to main content
Highlighted the two main use-cases with formatting and a bit of editing.
Source Link
Shyam Habarakada
  • 15.6k
  • 3
  • 38
  • 47

Undo git add for uncommitted changes with:

To unstage a specific file

git reset <file>

That will remove the file from the current index (the "about to be committed" list) without changing anything else.


 

To unstage all changes for all files:

To unstage all files from the current change set:

git reset

In old versions of Git, the above commands are equivalent to git reset HEAD <file> and git reset HEAD respectively, and will fail if HEAD is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:

"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).

Documentation: git reset

Undo git add for uncommitted changes with:

git reset <file>

That will remove the file from the current index (the "about to be committed" list) without changing anything else.


 

To unstage all changes for all files:

git reset

In old versions of Git, the above commands are equivalent to git reset HEAD <file> and git reset HEAD respectively, and will fail if HEAD is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:

"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).

Documentation: git reset

To unstage a specific file

git reset <file>

That will remove the file from the current index (the "about to be committed" list) without changing anything else.

To unstage all files from the current change set:

git reset

In old versions of Git, the above commands are equivalent to git reset HEAD <file> and git reset HEAD respectively, and will fail if HEAD is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:

"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).

Documentation: git reset

Shorten.
Source Link
Mateen Ulhaq
  • 26.6k
  • 20
  • 115
  • 147

You can undoUndo git add before commitfor uncommitted changes with:

git reset <file>

whichThat will remove itthe file from the current index (the "about to be committed" list) without changing anything else.

 

You can useTo unstage all changes for all files:

git reset

without any file name to unstage all due changes. This can come in handy when there are too many files to be listed one by one in a reasonable amount of time.

 

In old versions of Git, the above commands are equivalent to git reset HEAD <file> and git reset HEAD respectively, and will fail if HEAD is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:

"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).

Documentation: git reset

You can undo git add before commit with

git reset <file>

which will remove it from the current index (the "about to be committed" list) without changing anything else.

You can use

git reset

without any file name to unstage all due changes. This can come in handy when there are too many files to be listed one by one in a reasonable amount of time.

In old versions of Git, the above commands are equivalent to git reset HEAD <file> and git reset HEAD respectively, and will fail if HEAD is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:

"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).

Documentation: git reset

Undo git add for uncommitted changes with:

git reset <file>

That will remove the file from the current index (the "about to be committed" list) without changing anything else.

 

To unstage all changes for all files:

git reset
 

In old versions of Git, the above commands are equivalent to git reset HEAD <file> and git reset HEAD respectively, and will fail if HEAD is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:

"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).

Documentation: git reset

You can undo git add before commit with

git reset <file>

which will remove it from the current index (the "about to be committed" list) without changing anything else.

You can use

git reset

without any file name to unstage all due changes. This can come in handy when there are too many files to be listed one by one in a reasonable amount of time.

In old versions of Git, the above commands are equivalent to git reset HEAD <file> and git reset HEAD respectively, and will fail if HEAD is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:

"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).

Documentation: git reset

You can undo git add before commit with

git reset <file>

which will remove it from the current index (the "about to be committed" list) without changing anything else.

You can use

git reset

without any file name to unstage all due changes. This can come in handy when there are too many files to be listed one by one in a reasonable amount of time.

In old versions of Git, the above commands are equivalent to git reset HEAD <file> and git reset HEAD respectively, and will fail if HEAD is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:

"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).

You can undo git add before commit with

git reset <file>

which will remove it from the current index (the "about to be committed" list) without changing anything else.

You can use

git reset

without any file name to unstage all due changes. This can come in handy when there are too many files to be listed one by one in a reasonable amount of time.

In old versions of Git, the above commands are equivalent to git reset HEAD <file> and git reset HEAD respectively, and will fail if HEAD is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD, which is a stupid thing that you shouldn't do). This was changed in Git 1.8.2, though, so in modern versions of Git you can use the commands above even prior to making your first commit:

"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).

Documentation: git reset

Expanded.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132
Loading
add note that on old version of Git this didn't work prior to first commit
Source Link
Mark Amery
  • 150.3k
  • 87
  • 415
  • 465
Loading
Give `git reset` a full line, and remove claim about `git reset foo` and `git reset HEAD foo` being equivalent - this is false! The former works when HEAD is undefined (because you've just `git init`ed and haven't yet committed) or ambiguous (because you're a dick and created a branch called HEAD)
Source Link
Mark Amery
  • 150.3k
  • 87
  • 415
  • 465
Loading
Clarified response, so that it can stand on its own, and will not appear out of context.
Source Link
Jim Fell
  • 14.1k
  • 40
  • 131
  • 206
Loading
grammar and readability and pedantic accuracy
Source Link
iconoclast
  • 22.2k
  • 16
  • 106
  • 148
Loading
added some more info
Source Link
AlexStack
  • 17.2k
  • 21
  • 74
  • 106
Loading
Improved formatting.
Source Link
user456814
user456814
Loading
Made it clear that HEAD is optional.
Source Link
user456814
user456814
Loading
adds HEAD to the command, often optional, but still good to show here.
Source Link
iwein
  • 26.1k
  • 11
  • 74
  • 111
Loading
formatting
Source Link
takeshin
  • 50.2k
  • 32
  • 121
  • 165
Loading
Source Link
genehack
  • 139.2k
  • 1
  • 25
  • 25
Loading