Many times I mistakenly add unwanted files to the staging area using the git add .
command.
I wonder if there is a way I could completely disable this command, so that I only use git add file
?
Many times I mistakenly add unwanted files to the staging area using the git add .
command.
I wonder if there is a way I could completely disable this command, so that I only use git add file
?
undo git add unstage remove git rm --cached filename.txt git delete from index cancel from commit git reset filename.txt
Will remove a file named filename.txt from the current index, the "about to be committed" area, without changing anything else.
To undo git add . use git reset (no dot).
The important point about
git add .
is that it looks at the working tree and adds all those paths to the staged changes if they are either changed or are new and not ignored, it does not stage any 'rm' actions.If I understand the question correctly, you simply want to "undo" the git add that was done for that file.
If that is the case, then
will do the job.
Your modifications will be kept and the file will once again show up in the modified, but not yet staged set of
git status
.See the
git reset
man page for details.SVN re-education
You must unlearn what you have learned :)
You should run
git status
often. If files you want to ignore get listed as untracked files, you should then edit your.gitignore
file, so that those files actually become ignored. Becausegit add
doesn't affect ignored (and untracked) files, you will then be able to usegit add .
to stage all files of interest (and only those) in one fell swoop.How to completely disable
git add .
Git itself doesn't allow to do that, but if you really want to completely forbid the use of
git add .
(andgit stage .
, an exact equivalent), you can write a small wrapper aroundgit
(in your~/.<shell>rc
file) for that:You should add all files and directories you do not want under version control to the .gitignore file.
If you only want to not add everything, well then, don't do git add .