Disable git add. command
Re-educating SVN
I think this is a bad habit from svn, which by default only adds tracked files [...]
You have to wean what you've learned :)
You must run frequently git status
. If the files you want to ignore are listed as untracked files, you must then edit the file .gitignore
so that these files are effectively ignored. Since it git add
does not affect ignored (and unchecked) files, you can use it git add .
to create all files of interest (and only those) in one fell swoop.
How to completely disable git add .
Git itself doesn't allow you to do this, but if you really want to completely disallow usage git add .
(and git stage .
, the exact equivalent), you can write a little wrapper around git
(in your file ~/.<shell>rc
):
git() {
if [ "$1" = "add" -o "$1" = "stage" ]; then
if [ "$2" = "." ]; then
printf "'git %s .' is currently disabled by your Git wrapper.\n" "$1";
else
command git "$@";
fi
else
command git "$@";
fi;
}
source to share
The important point is that it looks at the working tree and adds all these paths to the staged changes, if they are either changed or new, and are not ignored, but not put any "rm" actions. git add .
If I understand the question correctly, you just want to "undo" the git add that was done for this file.
If so, then
git reset HEAD <file>
will do the job.
Your changes will be saved and the file will reappear in the modified but not yet delivered set git status
.
See the man page for details git reset
.
source to share