Languages
[Edit]
EN

Git remove added directory before git commit - revert git add -A

4 points
Created by:
sienko
683

In this article we would like to show how to undo directory added with 'git add -A' command.

Quick solution:

$ git reset our_directory_name/

Practical example. Remove entire intellij IDEA settings added to git changes by mistake:

$ git reset .idea/

Entire practical example - step by step:

1. git add -A

We add all of our files to git repo (coding ASAP).

root@DES /c/repos/java-html-sanitizer (main)
$ git add -A

2. git status

We see that we have unwanted changes directory .idea/

root@DES /c/repos/java-html-sanitizer (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   .idea/.name
        new file:   .idea/compiler.xml
        new file:   .idea/encodings.xml
        new file:   .idea/misc.xml
        modified:   pom.xml
        modified:   src/main/java/org/owasp/html/Encoding.java

3. git reset .idea/

We remove entire .idea/ directory from git changes.

root@DES /c/repos/java-html-sanitizer (main)
$ git reset .idea/

4. git status

Now, we see, we don't have .idea/ direcotry in git changes. We can commit our changes.

root@DES /c/repos/java-html-sanitizer (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   pom.xml
        modified:   src/main/java/org/owasp/html/Encoding.java

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Git

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join