GIT常见报错以及解决方法


在这里插入图片描述

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检测不到工作目录中的空文件夹

In the commit 5d82f46ca07f325ab972a1ea49fe16945f852d95, committer ‘xkcc (783133716@qq.com)’ does not match your user account.the following user name and email address is currently registered.Please change to the correct registration information ‘shengjianhua (shengjianhua@baidu.com)’

首先检查账户邮箱配置是否正确,检查方法:

git config --list

发现邮箱及帐号配置正确,但是git push时仍然报如题错误;

原因:git执行add、commit 时已经记录下了做了该操作时的帐号信息。

解决办法:

确认邮箱帐号配置无误后,将之前已经做的add、commit操作reset 掉,然后再重新add、commit即可;

备注:git 邮箱、帐号配置方法

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值