问题描述
很多时候,我错误地使用 git add。
命令将不需要的文件添加到暂存区域。
I想知道是否有一种方法可以完全禁用此命令,以便我只使用 git add file
?
SVN再教育
您必须清楚您所学到的内容:)
您应该经常运行 git status
。如果要忽略的文件被列为未跟踪文件,则应编辑 .gitignore
文件,以便实际上忽略这些文件。由于 git add
不影响忽略(和未跟踪)的文件,因此您可以使用 git add。
如何完全禁用 git add。
>
Git本身不允许这样做,但如果您真的想完全禁止使用 git add。
(和 git stage。
,完全相同),你可以在 git
你的〜/.& lt; shell> rc
文件):
git(){
if [$ 1=add-o$ 1=stage];那么
如果[$ 2=。 ]。那么
printf'git%s。'目前已被你的Git包装禁用。\\\
$ 1;
else
命令git$ @;
fi
else
命令git$ @;
fi;
}
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
?
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. Because git add
doesn't affect ignored (and untracked) files, you will then be able to use git 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 .
(and git stage .
, an exact equivalent), you can write a small wrapper around git
(in your ~/.<shell>rc
file) for that:
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;
}
这篇关于禁用git add。命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!