Add and rm of git common commands

Hello everyone, I am 17.

Add and delete the two most commonly used commands, this article explains with examples.

git add

Add content to the staging area.

git add file  添加一个文件
git add dir   添加一个目录,包括已经删除的文件
git *.c       添加以 .c 结尾的文件
git add .     添加当前目录所有文件,.gitignore 指定的文件除外
git add -u    添加暂存区已有的文件(包括删除操作),但不添加新增的文件

Do not add the file, only show whether the file exists or whether it is ignored.

Sometimes we modify the .gitignore file and want to see if it takes effect. For example, if we want to ignore *.cthe file

If ignoring takes effect, a prompt will be given when the add command is executed.

git add -n  a.c 

The following paths are ignored by one of your .gitignore files:

a.c

Allow adding ignored files

Our setting is to ignore *.c, but there is a config.c file that cannot be ignored. Because there is only this one file, and you don’t want to modify the gitignore file, you can force it to be added.

git add -f config.c 

After the addition is successful, changes to config.c will be tracked normally.

git rm

Delete files that are already being tracked. If the file is not tracked, rmjust do it.

Required if the file has been staged or committed git rm 命令.

git rm  a.txt            如果工作区没有修改, 删除工作区和暂存区文件
git rm --cached a.txt    如果工作区没有修改, 只删除暂存区文件。
git rm -f  a.txt         强制删除工作区和暂存区,不管工作区有没有修改
git rm -f --cached a.txt 强制删除暂存区,不管工作区有没有修改

If the deleted file has already been submitted, it needs to be submitted again to complete the deletion.

git commit -m '删除 a.txt'

Guess you like

Origin blog.csdn.net/m0_55635384/article/details/128964886