如何开始通过git提交到bitbucket - 没有看到变化

11 git version-control

也许我正在解决这个问题,但我正在按照git教程进行操作.我在bitbucket上有一个名为"testrepos"的存储库,我正在尝试使用它.

首先,我用它克隆它 git clone https://my_username@bitbucket.org/my_username/testrepos.git

现在,repo是空的,所以我创建了一个名为main.cpp的文件.然后我运行"git add main.cpp".如果我git status现在运行,我会看到有一个名为main.cpp的新文件要提交.

最后,我跑了git commit -m 'First commit'.有0个更改,0个插入和0个删除!为什么我的文件没有提交?我使用push,并pull为好.

编辑这是完整的日志:

Welcome to Git (version 1.7.7-preview20111014)

Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.

chris@EDI ~
$ cd git

chris@EDI ~/git
$ git clone https://my_username@bitbucket.org/my_username/testrepos.git
Cloning into testrepos...
Password:
warning: You appear to have cloned an empty repository.

chris@EDI ~/git
$ cd testrepos/

chris@EDI ~/git/testrepos (master)
$ git pull
Password:
Your configuration specifies to merge with the ref 'master'
from the remote, but no such ref was fetched.

chris@EDI ~/git/testrepos (master)
$ git add temp.cpp

chris@EDI ~/git/testrepos (master)
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   temp.cpp
#

chris@EDI ~/git/testrepos (master)
$ git commit -m 'Committing temp file'
[master (root-commit) 5d659df] Committing temp file
 Committer: unknown <chris@EDI.(none)>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 temp.cpp

chris@EDI ~/git/testrepos (master)
$ git pull
Password:
Your configuration specifies to merge with the ref 'master'
from the remote, but no such ref was fetched.

chris@EDI ~/git/testrepos (master)
$ git push
Password:
Everything up-to-date
Run Code Online (Sandbox Code Playgroud)

Mar*_*air 34

你真的需要做git push origin master,而不仅仅是git push.这是因为默认行为git push是将每个分支推送到远程端具有相同名称的分支,只要存在具有该名称的远程分支即可.在这种情况下,您的BitBucket存储库是完全空的(没有master分支,因为没有提交)因此没有分支将被git push或的默认行为推送git push origin.如果您这样做,您的推送将起作用:

git push origin master
Run Code Online (Sandbox Code Playgroud)

...但由于这是你的第一次推动,你应该这样做:

git push -u origin master
Run Code Online (Sandbox Code Playgroud)

...它还将master分支设置为分支origin的默认上游master分支.您只需要使用此命令形式一次.

  • +1因为它解释了为什么你必须做`git push origin master`一次. (2认同)