提交记录没有显示在Github上。

31
  • 我在github上创建了一个新的存储库。
  • 我选择了其中一个选项,添加了README.md文件。
  • 然后,我进入了我的硬盘上的项目目录。
  • 我运行了git init命令: 在/Users/myusername/github/myproject/.git/路径下初始化了一个空的Git存储库。
  • 我运行了"git add .",然后是"git commit -m 'project files'",结果显示如下:

[master (root-commit) ca52fe0] project files
 981 files changed, 257939 insertions(+), 0 deletions(-)
 create mode 100644 index.php
 create mode 100644 license.txt
 create mode 100644 readme.html
 create mode 100644 wp-activate.php
 ...
  • 然后我运行了 "git remote add origin https://github.com/myusername/myproject.git"
  • 接着我运行了 "git push origin master"
  • 然后我运行了 "git status",提示没有需要提交的内容
  • 但是当我查看代码库时,发现我的 "my project files" 提交记录并不存在。于是我运行了 git pull 命令,得到以下结果:

    You asked me to pull without telling me which branch you
    want to merge with, and 'branch.master.merge' in
    your configuration file does not tell me, either. Please
    specify which branch you want to use on the command line and
    try again (e.g. 'git pull <repository> <refspec>').
    See git-pull(1) for details.
    

    我已经运行了git push命令并再次检查,但我的提交仍未显示在GitHub存储库中。唯一能看到提交记录的方式是运行“git log”命令:

    MacBook-myproject myusername$ git log
    commit ca52fe090e6dbf1b6aa6ee51c3283efbe7549904
    Author: User <myemailaddress>
    Date:   Sat Jun 23 19:22:05 2012 -0400
    project files
    

    我尽可能按照Github的指导操作,但我做错了什么?


    当我运行上述命令时,我得到了这个结果:origin https://github.com/username/gitproject.git (fetch) origin https://github.com/username/gitproject.git (push) - JohnMerlino
    另外,初始的推送命令应为:git push -u origin master。-u 标志表示您的本地分支应成为远程分支的“跟踪”分支。 - Christopher Peisert
    是的,这些不是真实的网址。username指的是我的GitHub用户名,而projectname是实际的项目名称。 - JohnMerlino
    我还注意到,当我运行git pull时,它给了我一个错误,我已经添加到问题中。 - JohnMerlino
    这对我来说很困惑。以前我只需要使用 git push 就可以推送代码到远程仓库(或分支),而不需要显式地指定 origin 或者 branch。但现在我必须使用 git push -u origin master 才能成功推送。在执行 git remote -v 后,我的仓库地址看起来也没问题:origin git@github.com:brando90/ultimate-utils.git (push) 。那么我的 Git 配置出了什么问题呢?为什么我现在必须显式地指定推送的目标才能使用 git push 呢? - Charlie Parker
    4个回答

    28

    在你创建了Github存储库之后(即你可以在Github上查看它),你应该已经有了:

    1. 本地存储库设置:

    git init
    

    2. 已创建 README 文件并添加到仓库:

    touch README.md
    git add README.md 
    git commit -m 'first commit'
    

    3. 一个名为origin的远程仓库与你的仓库关联:

    git remote add origin https://github.com/username/repo.git
    

    4. 进行初始推送,将本地 README 文件复制到 GitHub 仓库:

    git push -u origin master
    
    如果你能在Github上查看你的代码库,那么它已经成功创建。在这种情况下,似乎你可能使用在线编辑工具在Github上编辑了README文件,这导致你的远程和本地分支分叉。

    在将本地更改推送到Github之前,你需要获取或拉取你的远程更改,本地合并更改(使用pull命令自动合并),然后将更改push到远程服务器。

    参见Pro Git:从远程服务器获取和拉取


    这让我感到困惑。以前我可以使用 git push 推送代码,而无需指定 origin(或 branch)。但现在我必须使用 git push -u origin master 才能推送代码。我通过运行 git remote -v 确认了我的 remote 信息是正确的:originn git@github.com:brando90/ultimate-utils.git (push)。那么我的 Git 配置出了什么问题呢?为什么我现在必须显式地指定推送到哪里,而 git push 不再起作用了? - Charlie Parker
    @CharlieParker 你看过这个问题了吗:未指定分支的“git push”的默认行为 - Christopher Peisert

    4
    当您在GitHub上创建仓库时,选择了初始化远程包含README.md文件。接下来的步骤是在终端中运行git clone https://github.com/username/repo.git。这时,在GitHub仓库上有了本地副本,接着将项目文件移入其中。运行git add *,然后git commit -m 'first commit',接着git push origin master。现在,您的更改应该在GitHub上可见。

    这让我感到困惑。我曾经可以使用 git push 推送代码,而不必指定 origin(或分支)。但现在我不能推送代码,除非执行 git push -u origin master。在执行 git remote -v 后,我的移除看起来很正常 originn git@github.com:brando90/ultimate-utils.git (push)...我的 git 配置发生了什么变化,以至于现在我必须明确指定推送的位置,而 git push 本身不再起作用? - Charlie Parker

    3

    在进行 git commit 后,您需要推送更改

    git push origin master 在主分支中推送更改

    git push origin branch_name 在次要分支中推送更改

    分支的完整工作流程:

    git checkout -b aosp_in_docker //checkout a branch and switch into it
    git branch // to check all branches current branch will have * sign
    git status //to check status of file
    git add .  //add untraced files
    git commit -a -m 'added a docker container'
    git push origin aosp_in_docker // push changes
    git staus // check if success
    

    这让我感到困惑。我曾经可以使用 git push 推送代码,而不必指定 origin(或分支)。但现在我不能推送代码,除非执行 git push -u origin master。在执行 git remote -v 后,我的移除看起来很正常 originn git@github.com:brando90/ultimate-utils.git (push)...我的 git 配置发生了什么变化,以至于现在我必须明确指定推送的位置,而 git push 本身不再起作用? - Charlie Parker

    0

    我认为大多数情况下,这种情况发生在不熟悉分支的新用户身上。 branches 。如果你有多个分支,请检查分支。我认为你正在将更改推送到另一个分支。


    目前你的回答不够清晰,请编辑并添加更多细节,以帮助其他人理解它如何回答问题。你可以在帮助中心找到有关如何编写好答案的更多信息。 - Community

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接