【发布时间】:2013-08-28 17:49:42
【问题描述】:
当我进入控制台时:
$ git add .
我明白了:
未添加任何内容。可能你想说“git add”?
【问题讨论】:
-
当你这样做时你的 cwd 是空的吗?
当我进入控制台时:
$ git add .
我明白了:
未添加任何内容。可能你想说“git add”?
【问题讨论】:
试试这个:$ git commit -am "Your commit message"
【讨论】:
git add 不是git commit。也许你可以在疯狂地提出一些建议之前就知道有什么区别。
add和commit!不是吗?
commit 的 -a 选项仅在创建提交之前将已跟踪到索引的文件添加到索引中。 OP 显然想添加新文件。
如果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
$
【讨论】:
试试git add -A。这应该将所有内容添加到暂存区域(新文件等)
来自手册:
与 -u 类似,但除了索引之外还匹配工作树中的文件。这意味着它将查找新文件以及暂存修改过的内容并删除不再在工作树中的文件。
【讨论】:
顺序应该是这样的:
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 以查看跟踪/未跟踪的更改。
【讨论】:
git status - 这会给你什么?
使用 git commit
$ git commit -m "Yeah am saving it!."
【讨论】:
git add-commit -m 'Yeah thats a commit'