1.问题如下:
echigh@huangchenggong:/mnt/e/work/workspace/withdraw_validdata_from_file/withdraw$ git push -u origin main
Username for 'https://github.com': echigh
Password for 'https://echigh@github.com':
To https://github.com/echigh/withdraw_frontbytes_of_file.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://github.com/echigh/withdraw_frontbytes_of_file.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.
2.原因是远程仓库有被更改过,和本地任一commit版本不匹配
参考:【狀況題】怎麼有時候推不上去... - 為你自己學 Git | 高見龍
3.解决办法:
1)先git pull合并远程的更改,然后再git push
2)直接用git push -f 强制覆盖远程仓库,我反正是不敢
4.于是,我是这样做的:
echigh@huangchenggong:/mnt/e/work/workspace/withdraw_validdata_from_file/withdraw$ git pull
remote: Enumerating objects: 22, done.
remote: Counting objects: 100% (22/22), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 21 (delta 13), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (21/21), 5.03 KiB | 66.00 KiB/s, done.
From https://github.com/echigh/withdraw_frontbytes_of_file
c6d3d5e..e50b1bc main -> origin/main
Merge made by the 'recursive' strategy.
README.md | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 README.md
然后再push:
echigh@huangchenggong:/mnt/e/work/workspace/withdraw_validdata_from_file/withdraw$ git push
Username for 'https://github.com': echigh
Password for 'https://echigh@github.com':
Enumerating objects: 44, done.
Counting objects: 100% (42/42), done.
Delta compression using up to 8 threads
Compressing objects: 100% (38/38), done.
Writing objects: 100% (38/38), 3.16 MiB | 994.00 KiB/s, done.
Total 38 (delta 19), reused 0 (delta 0)
remote: Resolving deltas: 100% (19/19), completed with 2 local objects.
To https://github.com/echigh/withdraw_frontbytes_of_file.git
e50b1bc..b7684a5 main -> main