GIT常见报错以及解决方法
- Changes not staged for commit
- 问题复现
- 原理
- 解决
- warning: adding embedded git repository
- 问题复现
- 原理
- 解决
- error: src refspec master does not match any
- 问题复现
- Changes not staged for commit
- 问题复现:
- 解决
Changes not staged for commit
问题复现
git commit -m "test"
提示信息为
On branch main
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)
(commit or discard the untracked or modified content in submodules)
modified: bdapp-qa/iOS-auto-tools (modified content)
modified: qa/auto-tools (modified content, untracked content)
Untracked files:
(use "git add <file>..." to include in what will be committed)
debt/
.vscode/
hackers/
output.txt
test/
原理
commit是将stage中的文件提交到本地仓库中(History或Repository)中。我们修改了代码,但只是在工作区修改的(Working Directory),stage中并没有修改,所以commit时检测不到提交到本地仓库的修改,于是提示“no changes added to commit”
解决
将这几个文件选择至少一个git add到暂存区,然后再commit即可
git add output.txt
git commit -m "1127"
warning: adding embedded git repository
问题复现
git add .
提示信息为:
warning: adding embedded git repository: hackers
error: 'test/' does not have a commit checked out
fatal: adding files failed
原理
添加了被嵌入的git仓库,根据提示,是由于test/文件夹里面的.git文件连接了另一个仓库,导致子文件夹的仓库信息和主文件夹的不一致,就是有个内嵌的子git仓库。
解决
cd test
rm -rf .git
error: src refspec master does not match any
问题复现
git push origin master:master
提示:
error: src refspec master does not match any
error: failed to push some refs to 'ssh://
原理:
本地没有master分支,或没有链接远程仓库或远程仓库没有master分支
解决方法:
修改当前本地分支名字为master
git branch -m master
Changes not staged for commit
问题复现:
git status
总是出现一些modified,并且无法通过git add或者git restore来修改
提示:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: baidu/baidu/bdapp-qa/iOS-auto-tools (modified content)
modified: baidu/baiduapp-android-qa/auto-tools (modified content, untracked content)
modified: debt (modified content)
解决
顺着路径进去,依次把所有的文件夹里面的.git文件删除即可,注意用rm -rf
git status检测不到工作目录中的空文件夹