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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7784951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:05:01  来源:igfitidea点击:

How to begin committing via git to bitbucket - Not seeing changes

gitversion-control

提问by Mark Longair

Perhaps I am going about this wrong, but I am following git tutorials as is. I have a repository on bitbucket called "testrepos" and I am trying to work with it.

也许我的做法是错误的,但我按原样遵循 git 教程。我在 bitbucket 上有一个名为“testrepos”的存储库,我正在尝试使用它。

First, I clone it with git clone https://[email protected]/my_username/testrepos.git

首先,我克隆它 git clone https://[email protected]/my_username/testrepos.git

Now, the repo is empty, so I made a file called main.cpp. I then run "git add main.cpp". If I run git statusnow, I see that there is a new file called main.cpp to be committed.

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

Finally, I run git commit -m 'First commit'. There are 0 changes, 0 insertions, and 0 deletions! Why are my files not committing? I am using pushand pullas well.

最后,我运行git commit -m 'First commit'. 有 0 次更改、0 次插入和 0 次删除!为什么我的文件没有提交?我正在使用pushpull

editHere is the full log:

编辑这是完整的日志:

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://[email protected]/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 [email protected]

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

回答by Mark Longair

You really do need to do git push origin master, rather than just git push. This is because the default behaviour of git pushis to push each branch to one with the same name on the remote side, so long as a remote branch with that name exists. In this case, your BitBucket repository is completely empty (without a masterbranch, since there are no commits) so no branches will be pushed by the default behaviour of git pushor git push origin. Your push will work if you do:

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

git push origin master

... but since this is your first push, you should do:

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

git push -u origin master

... which also sets the masterbranch in originto be the default upstream branch for your masterbranch. You only need to use this form of the command once.

...这也将master分支设置origin为您的master分支的默认上游分支。您只需要使用这种形式的命令一次。

回答by jespern

Try git push origin master.

试试git push origin master

回答by Mark Hildreth

Was the file you added empty? The message is showing you the number of changes files, and the number of lines inserted and deleted. If you just added an empty file, git doesn't count that as "changed" in the numbers it's generating. It DOES, however, commit the file.

你添加的文件是空的吗?该消息向您显示更改文件的数量以及插入和删除的行数。如果您只是添加了一个空文件,则 git 不会将其计算为它生成的数字中的“已更改”。但是,它确实提交了文件。

Try to push back up to bitbucket, and view the repository file listing in a web browser. You should see your file there.

尝试回推到 bitbucket,并在 Web 浏览器中查看存储库文件列表。你应该在那里看到你的文件。

回答by Paul G

I have had this issue as well, and I have seen a lot of unhelpful advice. Finally, I broke down and read the code for git-pull and git-fetch. In my case, the problem is caused by having "tagopt = --tags" in the configuration file for the remote in question. This seems to cause git-fetch to do "automated tag following" which has a bad side-effect of truncating the FETCH_HEAD file in some cases. This in turn causes git-pull to fail with the error:

我也遇到过这个问题,我看到了很多无用的建议。最后,我分解并阅读了 git-pull 和 git-fetch 的代码。在我的情况下,问题是由在相关遥控器的配置文件中包含“ tagopt = --tags”引起的。这似乎导致 git-fetch 执行“自动标记跟踪”,这在某些情况下具有截断 FETCH_HEAD 文件的不良副作用。这反过来导致 git-pull 失败并出现错误:

Your configuration specifies to merge with the ref 'master' from the remote, but no such ref was fetched.

您的配置指定与来自远程的 ref 'master' 合并,但未获取此类 ref。

I am really not confident enough with the internals of git to say if this is a bug or intended behavior or just me not understanding git very well. However, removing "tagopt" settings from my config files has solved the problem for me in all instances.

我对 git 的内部结构真的没有足够的信心来判断这是一个错误还是预期的行为,或者只是我不太了解 git。但是,从我的配置文件中删除“ tagopt”设置在所有情况下都为我解决了这个问题。

Note, this is particularly confusing because manually running "git fetch --tags ..." takes a different code path and FETCH_HEAD is left in good shape.

请注意,这尤其令人困惑,因为手动运行“git fetch --tags ...”采用不同的代码路径,并且 FETCH_HEAD 保持良好状态。

(I am running git version 1.7.4.1)

(我正在运行 git 版本 1.7.4.1)

回答by bharv14

git push -u origin --all

git push -u origin --all

for first time

第一次

git push origin --all

git push origin --all

afterwards

然后

is whats listed on bitbucket 101

是什么在 bitbucket 101 上列出

https://confluence.atlassian.com/display/BITBUCKET/Create+a+repository

https://confluence.atlassian.com/display/BITBUCKET/Create+a+repository