git 提交未显示在 github 上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11173971/
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-10 14:00:24  来源:igfitidea点击:

commits not showing up on github

gitgithub

提问by JohnMerlino

  • I created a new repository on github.
  • I selected one of the options that added a README.md.
  • I then cd into the project on my hard drive.
  • I ran git init: Initialized empty Git repository in /Users/myusername/github/myproject/.git/
  • I ran "git add ." and then "git commit -m 'project files'", which responded with this:

    [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
     ...
    
  • I then ran "git remote add origin https://github.com/myusername/myproject.git"
  • I then ran "git push origin master"
  • I then ran "git status" which said nothing to commit
  • 我在 github 上创建了一个新的存储库。
  • 我选择了添加 README.md 的选项之一。
  • 然后我 cd 进入我硬盘上的项目。
  • 我运行 git init: Initialized empty Git repository in /Users/myusername/github/myproject/.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”,它没有说要提交

But I look at repo and my "my project files" commit is not there. So then I ran git pull and got this:

但是我查看 repo 并且我的“我的项目文件”提交不在那里。然后我运行 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.

and then git push and checked again and still my commits are not on github repo. The only time I can see the commit is when I run "git log":

然后 git push 并再次检查,但我的提交仍然不在 github repo 上。我唯一能看到提交的时间是当我运行“git log”时:

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

I followed github directions best that I could. What am I doing wrong?

我尽可能地遵循 github 的指示。我究竟做错了什么?

采纳答案by Christopher Peisert

After your Github repository has been created (i.e. you can view it on Github), then you should already have:

在您的 Github 存储库创建后(即您可以在 Github 上查看它),那么您应该已经拥有:

  • Local repository set up: git init
  • README file created and added to the repository:
  • 本地存储库设置: git init
  • 创建并添加到存储库的自述文件:

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

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

  • A remote called originlinked to your repository:
  • 远程调用origin链接到您的存储库:

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

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

  • An initial push, which copied your local README to your Github repository:
  • 初始推送,将您的本地 README 复制到您的 Github 存储库:

git push -u origin master

git push -u origin master

If you can view your repository on Github, then it has been successfully created. In this case it looks like you may have edited your README file on Github using the online editing tools, which caused your remote and local branches to diverge. Before you can push your local changes to Github, you need to fetch or pull your remote changes, merge the changes locally (merging is automatic with pull), and then push to the remote.

如果你可以在 Github 上查看你的仓库,那么它就已经创建成功了。在这种情况下,您似乎使用在线编辑工具在 Github 上编辑了 README 文件,这导致您的远程和本地分支出现分歧。在将本地更改推送到 Github 之前,您需要获取或拉取远程更改,在本地合并更改(使用 自动合并pull),然后推送到远程。

See Pro Git: Fetching and Pulling from Your Remotes

请参阅 Pro Git:从您的遥控器中获取和拉取

回答by Zachariah Moreno

When you created the repository on GitHub you selected initializes remotely containing a README.md file. The next step would be to run git clone https://github.com/username/repo.gitin your terminal. At this point you have a local copy on the GitHub repository, so you would then move in your project files. Run git add *then git commit -m 'first commit'then git push origin master. Your changes should now be visible on GitHub.

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

回答by Hitesh Sahu

After a git commit you need to push the changes

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

git push origin master to pushin master branch

git push origin master to push在主分支

git push origin branch_name to pushin secondary branch

git push origin branch_name to push在二级分支

Complete work flow for a branch:

一个分支的完整工作流程:

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