【问题标题】:git commit -a -m gives error for file not being trackedgit commit -a -m 给出文件未被跟踪的错误
【发布时间】:2021-06-30 17:55:53
【问题描述】:

我正在学习使用 git,并且正在玩分支。 我创建了一个文件“test.rb”并在“测试”分支上提交了一个版本。

作为“主人”,我使用git commit -a -m 'msg' 并收到此消息:

On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        test.rb

nothing added to commit but untracked files present (use "git add" to track)

我不明白为什么,因为“-a”标志应该将所有内容添加到暂存并提交。

我错过了什么? 谢谢!

【问题讨论】:

  • gives error - 这不是错误消息。未跟踪的文件不会使用-a 自动添加,这是暗示但未说明这是您所期望的,您可以编辑问题以澄清一下吗?
  • git status 应该会告诉您是否确实有任何其他未跟踪的文件。

标签: git commit git-branch git-commit branching-and-merging


【解决方案1】:

由于test.rb文件还没有被git跟踪,所以需要添加 首先使用git add

git add test.rb
git commit -m "msg"

之后,如果您对该文件添加更改,您可以使用-a 选项提交您的更改

git commit -am "msg"

git 帮助中-a 标志的描述也强调了这一点:

$ git commit --help
-a, --all
           Tell the command to automatically stage files that have been
           modified and deleted, but new files you have not told Git about
           are not affected.

【讨论】:

    猜你喜欢
    • 2012-01-18
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 2011-04-01
    • 2017-08-04
    • 2017-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多