GitHub
有时候 Git push origin master 会报错, 如下:
- $ Git push origin master
- To GitHub.com:smartBBer/LeetCode.Git
- ! [rejected] master -> master (fetch first)
- error: failed to push some refs to 'git@github.com:smartBBer/LeetCode.git'
- hint: Updates were rejected because the remote contains work that you do
- hint: not have locally. This is usually caused by another repository pushing
- hint: to the same ref. You may want to first integrate the remote changes
- hint: (e.g., 'git pull ...') before pushing again.
- hint: See the 'Note about fast-forwards' in 'git push --help' for details.
错误原因很简单: 本地库和 GitHub 中的库不同步, 解决办法有两种.
第一种解决方法 (不要轻易使用)
加上 -f, 强制推送上去, 这时你的 GitHub 上的库会以本地同步,
- $ Git push -f
- Enumerating objects: 35, done.
- Counting objects: 100% (35/35), done.
- Delta compression using up to 4 threads
- Compressing objects: 100% (24/24), done.
- Writing objects: 100% (35/35), 6.35 KiB | 325.00 KiB/s, done.
- Total 35 (delta 6), reused 6 (delta 1)
- remote: Resolving deltas: 100% (6/6), done.
- To GitHub.com:smartBBer/LeetCode.Git
- + 0794cc5...80639ea master -> master (forced update)
第二种解决方法 (推荐)
使用 Git pull --rebase origin master 合并 GitHub 和 本地 的库, 本地会多出之前不同步的文件, 在使用 Git push -u origin master 推送到 GitHub 库中.
- $ Git pull --rebase origin master
- $ Git push origin master
来源: http://www.jianshu.com/p/86adb5e6bbfc