【问题标题】:Unable to commit in Git [closed]无法在 Git 中提交 [关闭]
【发布时间】:2013-08-28 17:49:42
【问题描述】:

当我进入控制台时:

$   git add .

我明白了:

未添加任何内容。可能你想说“git add”?

【问题讨论】:

  • 当你这样做时你的 cwd 是空的吗?

标签: git git-add


【解决方案1】:

试试这个:$ git commit -am "Your commit message"

【讨论】:

  • 据我所知git add 不是git commit。也许你可以在疯狂地提出一些建议之前就知道有什么区别。
  • 这里你可以通过一个命令完成add和commit!不是吗?
  • commit 的 -a 选项仅在创建提交之前将已跟踪到索引的文件添加到索引中。 OP 显然想添加新文件。
  • 是的!它不会添加未跟踪的文件。
【解决方案2】:

没有什么可提交的

如果git add . 不做任何事情,则有两种可能:

  • 你所在的目录是空的
  • 文件夹中的所有内容都已被跟踪且未更改或被忽略

例如有一个空文件夹:

$ git add .
$ git status
# On branch master
#
# Initial commit
#
$ ls -la
drwxrwxr-x  3 andy andy 4096 Aug 26 11:34 .
drwxrwxrwt 11 andy andy 4096 Aug 26 11:34 ..
drwxrwxr-x  7 andy andy 4096 Aug 26 11:34 .git

或者,如果所有内容都已被跟踪且未更改:

$ touch foo
$ git add foo
$ git commit -m "adding foo"
[master (root-commit) d27092b] adding foo
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 foo
$ git add .
$ git status
# On branch master
nothing to commit, working directory clean
$ ls -la
drwxrwxr-x  3 andy andy 4096 Aug 26 11:34 .
drwxrwxrwt 11 andy andy 4096 Aug 26 11:34 ..
-rw-rw-r--  1 andy andy    0 Aug 26 11:35 foo
drwxrwxr-x  7 andy andy 4096 Aug 26 11:34 .git

请注意,git status 没有报告任何更改。

忽略?

如果一个文件/文件夹被忽略,那么 git 会忽略它:)

但是您仍然可以显式添加它:

$ echo "bar" > .gitignore
$ touch bar
$ git add bar
The following paths are ignored by one of your .gitignore files:
bar
Use -f if you really want to add them.
fatal: no files added
$ git add -f bar
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   bar
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .gitignore
$

【讨论】:

    【解决方案3】:

    试试git add -A。这应该将所有内容添加到暂存区域(新文件等)

    来自手册:

    与 -u 类似,但除了索引之外还匹配工作树中的文件。这意味着它将查找新文件以及暂存修改过的内容并删除不再在工作树中的文件。

    【讨论】:

      【解决方案4】:

      顺序应该是这样的:

      1) 启动一个分支:git checkout -b my_cool_branch
      2) 在该分支上做一些事情
      3) 添加您对提交队列所做的更改:git add .
      4) 提交您添加到队列中的内容:git commit -m "i'm adding stuff!"

      (可选)
      5) 切换回 master(或任何您的主分支):git checkout master
      6) 推送您的本地提交到你的github:git push origin master

      您看到的错误让我认为您已跳过第 2 步 - 您确定已进行更改吗?运行 git status 以查看跟踪/未跟踪的更改。

      【讨论】:

      • @ dax 我对 git 很陌生。我已经完成了 2 个任务。现在我想提交这两个任务......这些是给我提交的说明...... .....请检查:说出您在 AS-3 中工作的票号,那么您的 git 提交应该如下所示 git add 。 git commit -am "AS3 - 变更描述" git push origin master
      • 输入git status - 这会给你什么?
      【解决方案5】:

      使用 git commit

      $ git commit -m "Yeah am saving it!."
      

      【讨论】:

      • @Shankar 是否需要添加 $ git add??? 或者我可以直接添加 $ git commit -m "是的,我正在保存它!。"谢谢
      • @Neha,您甚至可以同时进行添加和保存。 git add-commit -m 'Yeah thats a commit'
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      • 2015-01-04
      • 2015-12-06
      • 1970-01-01
      • 2013-07-14
      • 1970-01-01
      相关资源
      最近更新 更多