299 字
1 分钟
Git如何在上传多个文件时排除少部分文件
场景
修改了多个文件,但是这些文件中有一个文件不想提交,单个添加太麻烦
解决
先全部添加
git add .
然后查看暂存区,记下想排除的文件名
git status
从暂存区移除不想提交的文件
git reset HEAD <不想要的文件>
验证暂存区,看不想要的文件是否移除
git status
提交并推送
git commit -m "提交说明"git push
实际操作
❯ git add .❯ git statusOn branch masterYour branch is up to date with 'origin/master'.
Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: mx-space部署记录.md new file: test1.md new file: test2.md new file: test3.md
❯ git reset HEAD mx-space部署记录.mdUnstaged changes after reset:M mx-space部署记录.md❯ git statusOn branch masterYour branch is up to date with 'origin/master'.
Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: test1.md new file: test2.md new file: test3.md
Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: mx-space部署记录.md❯ git push
如果移除错了可以通过git add <文件名>
再将单独的文件添加进来
如果想全部移除,可以直接使用git reset
指令
Git如何在上传多个文件时排除少部分文件
https://fuwari.cbba.top/posts/git如何在上传多个文件时排除少部分文件/