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/yourBranch
: git 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
时的默认选项。)