错误记录Git 使用报错 ( no changes added to commit (use “git add“ and/or “git commit -a“) )

Posted 韩曙亮

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了错误记录Git 使用报错 ( no changes added to commit (use “git add“ and/or “git commit -a“) )相关的知识,希望对你有一定的参考价值。





一、报错信息



修改了 Git 版本库中的 file1.txt 文件 , 直接执行

git commit -m "modify file1"

命令 , 尝试提交版本库 , 提示如下信息 ;


报错信息 :

D:\\Git\\git-learning-course>git commit -m "modify file1"
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
  (use "git push" to publish your local commits)

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:   file1.txt

no changes added to commit (use "git add" and/or "git commit -a")

D:\\Git\\git-learning-course>


文件修改 :





二、解决方案



方案一 :

提交代码时 , 需要先 执行 git add 命令 将文件添加到 " 暂存区 " , 然后执行 git commit 命令 将文件提交到 " 版本库 " ;


直接 执行 git commit 命令 将文件提交到 " 版本库 " 是不行的 ;


方案二 :

也可以使用 git commit -a 命令 , 省去 git add 步骤 ;

如 : 修改了 file2.txt 文件 , 执行

git commit -a -m "modify file2"

命令 , 可以直接提交版本库 ;

以上是关于错误记录Git 使用报错 ( no changes added to commit (use “git add“ and/or “git commit -a“) )的主要内容,如果未能解决你的问题,请参考以下文章