GIT常见报错以及解决方法

GIT常见报错以及解决方法

  • Changes not staged for commit
    • 问题复现
    • 原理
    • 解决
  • warning: adding embedded git repository
    • 问题复现
    • 原理
    • 解决
  • error: src refspec master does not match any
    • 问题复现
  • Changes not staged for commit
    • 问题复现:
    • 解决
    • In the commit 5d82f46ca07f325ab972a1ea49fe16945f852d95, committer 'xkcc ([email protected])' does not match your user account.the following user name and email address is currently registered.Please change to the correct registration information 'shengjianhua ([email protected])'

GIT常见报错以及解决方法_第1张图片

Changes not staged for commit

问题复现

git commit -m "test"

提示信息为

On branch main
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git restore ..." 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 ..." 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常见报错以及解决方法_第2张图片
将这几个文件选择至少一个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 ..." to update what will be committed)
  (use "git restore ..." 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 ([email protected])’ does not match your user account.the following user name and email address is currently registered.Please change to the correct registration information ‘shengjianhua ([email protected])’

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

git config --list

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

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

解决办法:

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

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

你可能感兴趣的:(git)