My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Tuesday, March 23, 2021

How to undo a Git Add Command befor any commit

 This is a very simple mistake by developers that they accidentally add a file locally using the Git add command.


Sometimes a git add * command also adds all the files. What to do in such situation is the aim of this post.


Let's take an example:

Suppose, I mistakenly added files to Git using the command:

git add anwar-jamal-faiz.txt

I have not yet run git commit. Is there a way to undo this, so these files won't be included in the commit?

You can undo git add before commit with


git reset <file>

eg: git reset anwar-jamal-faiz.txt

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


You can also 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.


Cheers ;)


2 comments: