git 如何使用 master 更新本地 repo?

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

How to update local repo with master?

gitsvngithub

提问by user3898238

I am used to using SVN and only recently switched to GitHub.

习惯用SVN,最近才转用GitHub。

I am trying to update some files in a GitHub repo, but I get this message:

我正在尝试更新 GitHub 存储库中的一些文件,但收到以下消息:

To https://github.com/.../
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/.../'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I have tried commands like git fetch originand git pull, but none of these make it so my current branch is not behind.

我尝试过像git fetch originand这样的命令git pull,但这些命令都没有成功,所以我当前的分支并不落后。

In SVN I'd just do svn updateand then commit my changes.

在 SVN 中,我只是做svn update然后提交我的更改。

I've also tried git pull origin, but I get a strange text message popping up and I have no idea how to interface with it: Updating a local repository with changes from a Github repository

我也试过了git pull origin,但我收到一条奇怪的短信,我不知道如何与之交互:使用 Github 存储库中的更改更新本地存储库

回答by Breen ho

  1. Check your current branch with the command:

    git branch

    It will show your current branch name with an asterisk (*) next the name.

  2. Then update your local branch with the remote branch:

    git pull origin branchname(This is the branch name with asterisks)

  3. Now you can push your code to the remote repository if you have already committed your local changes with the command:

    git push origin branchname

  1. 使用以下命令检查您当前的分支:

    git 分支

    它将显示您当前的分支名称,名称旁边带有星号 (*)。

  2. 然后使用远程分支更新本地分支:

    git pull origin branchname(这是带星号的分支名称)

  3. 现在,如果您已经使用以下命令提交了本地更改,则可以将代码推送到远程存储库:

    git push origin 分支名

If you haven't committed yet, first do a commitand then do a git pulland push.

如果您还没有提交,请先提交,然后执行 git pullpush

回答by Justin Howard

It is normal for git to open an editor when you pull. This is because you are merging in the changes from the remoteto your local branch.

git在拉的时候打开编辑器是正常的。这是因为您正在合并从远程到本地分支的更改

When you pull, git detects whether it needs to merge your local branch with the remote branch. If it needs to merge, it will do so and present you with the opportunity to write a custom message for the merge commit. At that point, you can choose to just close the editor, and git will finish the process.

在 pull 时,git 会检测是否需要将您的本地分支与远程分支合并。如果它需要合并,它将这样做并为您提供为合并提交编写自定义消息的机会。此时,您可以选择仅关闭编辑器,然后 git 将完成该过程。

Basically, all you had to do is close the editorand you would have been done.

基本上,您所要做的就是关闭编辑器,您就可以完成了。

Essentially, git is doing the following:

本质上,git 正在执行以下操作:

#Download all the commits from the remote
git fetch origin

# Merge in the commits from the remote to your local branch
# If anything needs merging, this will open a text editor
git merge origin/master master