Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

git - git错误:无法将一些引用推送到(git error: failed to push some refs to)

For some reason, I can't push now, whereas I could do it yesterday.

(由于某种原因,我现在不能推动,而昨天却可以。)

Maybe I messed up with configs or something.

(也许我搞砸了配置或其他东西。)

This is what happens:

(这是发生了什么:)

When I use the git push origin master

(当我使用git push origin master)

gitbashscr

What my working directory and remote repository looks like:

(我的工作目录和远程存储库如下所示:)

在此处输入图片说明

  ask by leipz translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:

(如果您在本地工作时,GitHub存储库中看到有新提交提交,建议您使用:)

git pull --rebase
git push

The full syntax is:

(完整语法为:)

git pull --rebase origin master
git push origin master

With Git 2.6+ (Sept. 2015), after having done (once)

(完成一次之后, 使用Git 2.6+ (2015年9月))

git config --global pull.rebase true
git config --global rebase.autoStash true

A simple git pull would be enough.

(一个简单的git pull就足够了。)

That way, you would replay (the --rebase part) your local commits on top of the newly updated origin/master (or origin/yourBranch : git pull origin yourBranch ).

(这样,您将在新近更新的origin/master (或origin/yourBranchgit pull origin yourBranch )之上重播( --rebase部分)本地提交。)

See a more complete example in the chapter 6 Pull with rebase of the Git Pocket Book .

(请参阅《 Git Pocket Book第6章重装基础》中的更完整示例。)

I would recommend a:

(我建议:)

git push -u origin master

That would establish a tracking relationship between your local master branch and its upstream branch.

(这将在本地主分支与其上游分支之间建立跟踪关系。)
After that, any future push for that branch can be done with a simple:

(之后,可以使用以下简单的方法完成对该分支的将来任何推送:)

git push

See " Why do I need to explicitly push a new branch? ".

(请参阅“ 为什么需要显式推送新分支? ”。)


Since the OP already reset and redone its commit on top of origin/master :

(由于OP已经重置并origin/master之上重做其提交 :)

git reset --mixed origin/master
git add .
git commit -m "This is a new commit for what I originally planned to be amended"
git push origin master

There is no need to pull --rebase .

(无需pull --rebase 。)

Note: git reset --mixed origin/master can also be written git reset origin/master , since the --mixed option is the default one when using git reset .

(注意: git reset --mixed origin/master也可以写成git reset origin/master ,因为--mixed选项是使用git reset时的默认选项。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...