Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo “git add <dir>”?

Tags:

git

git-reset

People also ask

How do I Unstage a folder?

In order to unstage all files and directories, execute “git reset” and they will be removed from the staging area back to your working directory.

How do you undo add and commit?

Undoing a commit If you have modified, added and committed changes to a file, and want to undo those changes, then you can again use git reset HEAD~ to undo your commit.

How do I remove a directory from a git branch?

Deleting directory in Git To delete a directory from git repository, we can use the git command followed by rm command , -r flag and the name of your directory.


To remove a directory and everything inside it from the index,

git rm --cached -r dir

The --cached switch makes git rm operate on the index only and not touch the working copy. The -r switch makes it recursive.


You will want to use git rm --cached -r <dir>. this command will remove the staged directory contents from the index.

if the directory was already tracked you have to find new and old files manually and unstage them …

Probably run git reset <dir> after that to reset existing (and already tracked) files inside the directory.


Update 2019:

Simply run git reset directory, it will unstage all newly added files.


Unstage directory

$ git reset <dir>

Unstages all the files and folders I staged with:

$ git add <dir>

Confirm directory unstaged

In order to confirm the removal of the directory and its contents from staging (ie "Changes to be committed"), run the below:

$ git status

or

$ git diff --staged --name-only 

to confirm that none of the folders or files previously staged are still staged.


Use find and xargs:

find dir -type f | xargs git reset