EN
Git remove added directory before git commit - revert git add -A
4 points
In this article we would like to show how to undo directory added with 'git add -A' command.
Quick solution:
xxxxxxxxxx
1
$ git reset our_directory_name/
Practical example. Remove entire intellij IDEA settings added to git changes by mistake:
xxxxxxxxxx
1
$ git reset .idea/
Entire practical example - step by step:
1. git add -A
We add all of our files to git repo (coding ASAP).
xxxxxxxxxx
1
root@DES /c/repos/java-html-sanitizer (main)
2
$ git add -A
2. git status
We see that we have unwanted changes directory .idea/
xxxxxxxxxx
1
root@DES /c/repos/java-html-sanitizer (main)
2
$ git status
3
On branch main
4
Your branch is up to date with 'origin/main'.
5
6
Changes to be committed:
7
(use "git restore --staged <file>..." to unstage)
8
new file: .idea/.name
9
new file: .idea/compiler.xml
10
new file: .idea/encodings.xml
11
new file: .idea/misc.xml
12
modified: pom.xml
13
modified: src/main/java/org/owasp/html/Encoding.java
3. git reset .idea/
We remove entire .idea/ directory from git changes.
xxxxxxxxxx
1
root@DES /c/repos/java-html-sanitizer (main)
2
$ git reset .idea/
4. git status
Now, we see, we don't have .idea/ direcotry in git changes. We can commit our changes.
xxxxxxxxxx
1
root@DES /c/repos/java-html-sanitizer (main)
2
$ git status
3
On branch main
4
Your branch is up to date with 'origin/main'.
5
6
Changes to be committed:
7
(use "git restore --staged <file>..." to unstage)
8
modified: pom.xml
9
modified: src/main/java/org/owasp/html/Encoding.java