git git拒绝推送非快进
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16899243/
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
git rejected push non-fast-forward
提问by JohnJ
I am quite new to git, and I had been working on a small side project for the last 2 months and had been pushing stuff onto bitbucket with no problems. A couple of days ago, I zipped my project folder (since I had to reinstall my Linux OS) and now unzipped this after my reinstallation of Linux OS.
我对 git 很陌生,过去 2 个月我一直在做一个小项目,并且一直在将东西推到 bitbucket 上,没有任何问题。几天前,我压缩了我的项目文件夹(因为我必须重新安装 Linux 操作系统),现在在重新安装 Linux 操作系统后解压缩它。
So, now, I went to my project folder, kept happily working and finally did:
所以,现在,我去了我的项目文件夹,继续愉快地工作,最后做了:
git add -A && git commit -m "modified code" && git push origin master
..which is what I usually do..
..这是我通常做的..
and I get:
我得到:
To https://[email protected]/johnsproject/proj.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://[email protected]/johnsproject/proj.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I have had a look at a few SO questions where they suggest the use of a force flag -f
- but I am unsure if I should be doing this.
我看过一些 SO 问题,他们建议使用强制标志-f
- 但我不确定我是否应该这样做。
p.s: I am on the master branch - which is the only
branch on my repo.
ps:我在 master 分支上 - 这是only
我的 repo 上的分支。
Would really appreciate if anyone could point me in the right direction here.
如果有人能在这里指出我正确的方向,我将不胜感激。
Thanks.
谢谢。
回答by Klas Mellbourn
There are changes in the central repository that you must pull before you can push. Do
您必须先拉取中央存储库中的更改,然后才能推送。做
git add -A
git commit -m "my local changes"
git pull
Resolve any conflicts. Thendo
解决任何冲突。然后做
git push
Alternatively, if you have no valuable modifications locally, you can create a new clone of your repo, and start working from there:
或者,如果您在本地没有有价值的修改,您可以创建一个新的 repo 克隆,然后从那里开始工作:
git clone https://[email protected]/johnsproject/proj.git new_repo_dir
回答by Ganye
Try doing
尝试做
git pull origin master
git add -A
git commit -m "modified code"
git push origin master
Your local repository is likely out of sync with the remote repository.
您的本地存储库可能与远程存储库不同步。
回答by Marcell Almeida
I had the same problem. I fixed by using the git push -f
command which forces the update.
我有同样的问题。我通过使用git push -f
强制更新的命令进行了修复。
回答by Feno Ortocus
works for me git push --set-upstream origin master -f
对我来说有效 git push --set-upstream origin master -f
回答by SystemDZ
in my case was new file from git repository not added, and this was the solution 1. git status (just to check) 2. git add . 3. git push -u master origin
在我的情况下,未添加来自 git 存储库的新文件,这是解决方案 1. git status (只是为了检查) 2. git add 。3. git push -u master origin
回答by Hanna Kogut
You can try git pull, after that git commit in studio, and after that git push origin branch name.
您可以尝试 git pull,在 studio 中的 git commit 之后,以及在 git push origin 分支名称之后。