in Technology by
How do I undo 'git add' before commit?

1 Answer

0 votes
by

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).

Related questions

0 votes
    How do I revert from my current state to a snapshot made on a certain commit? If I do git log, then I get ... , i.e. commit 0d1d7fc? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    How to Undo a Git merge that hasn't been pushed yet?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    In Git how do you revert a commit that has already been pushed and made public?...
asked Nov 2, 2020 in Technology by JackTerrance
0 votes
    Does anybody know how to easily undo a git rebase? The only way that comes to mind is to go at it manually: ... replayed. Not only one. Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I have made a commit and discarded it. I can still retrieve that commit using git reflog. A. True B. False...
asked Dec 24, 2022 in Education by JackTerrance
0 votes
    I am a little bit puzzled on the question of whether to commit .tfstate files to Git or not. The Terraform ... if so, why? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    In case of any shut down during transaction before commit which of the following statement is done ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    The command git add [--all|-A] appears to be identical to git add .. Is this correct? If not, how do they differ?...
asked Jan 8, 2021 in Technology by JackTerrance
0 votes
    I have used "traditional" version control systems to maintain source code repositories on past projects. I ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    How to Commit only part of a file in Git?...
asked Jan 8, 2021 in Technology by JackTerrance
0 votes
    How to revert a Git repository to a previous commit?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    How to modify existing, unpushed commit messages in git?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    How will you find out what all files have been changed in a particular Git commit?...
asked Nov 4, 2020 in Technology by JackTerrance
0 votes
    As asked in this question, I also want to know how to resolve a conflicting git stash pop without ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    What does the command git add . do? A. Adds all the files to repo B. Adds all the files to the staging area C. Adds all the files to the local directory D. None of the options...
asked Dec 17, 2022 in Education by JackTerrance
...