创建于:20201225
修改于:20201225

1、背景

一直没有系统的研究对git对文件的添加和删除。在此试验并记录。

2、添加文件、添加目录
2.1 git add 介绍
$ git add -h
usage: git add [<options>] [--] <pathspec>...

    -n, --dry-run         dry run
    -v, --verbose         be verbose

    -i, --interactive     interactive picking
    -p, --patch[=<patch-mode>]
                          select hunks interactively
    -e, --edit            edit current diff and apply
    -f, --force           allow adding otherwise ignored files
    -u, --update          update tracked files
    --renormalize         renormalize EOL of tracked files (implies -u)
    -N, --intent-to-add   record only the fact that the path will be added later
    -A, --all             add changes from all tracked and untracked files
    --ignore-removal      ignore paths removed in the working tree (same as --no-all)
    --refresh             don't add, only refresh the index
    --ignore-errors       just skip files which cannot be added because of errors
    --ignore-missing      check if - even missing - files are ignored in dry run
    --chmod (+|-)x        override the executable bit of the listed files
2.2 git add 文件

比如增加一个add_test.txt文件

git add add_test.txt
git commit -m "add commd test"
git push
2.3 git add 文件夹

git add 无法添加一个空文件夹。

git add bin
git commit -m "add directory bin test"
git push
3、删除文件、删除目录
3.1 git rm 介绍
$ git rm -h
usage: git rm [<options>] [--] <file>...

    -n, --dry-run         dry run
    -q, --quiet           do not list removed files
    --cached              only remove from the index
    -f, --force           override the up-to-date check
    -r                    allow recursive removal
    --ignore-unmatch      exit with a zero status even if nothing matched
3.2 git rm 文件
git rm add_test.txt
git commit -m "remove add_test.txt"
git push
3.3 git rm 文件夹
git rm bin -r -f
git commit -m "delete bin directory"
git push

如果删除了一个不存在的文件夹,则提示:

$ git rm bin/ -r -f
fatal: pathspec 'bin/' did not match any files
4、参考链接
4.1 删除操作

git 命令删除文件操作
git 删除指定文件夹
git操作基础:删除文件夹

4.2 高级操作及问题

Git高级教程,常见工程问题笔记
大坑:git无法添加一个空的文件夹
git操作时提示:fatal: pathspec ‘README’ did not match any files 的处理办法

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐