windows git push報錯: ! [rejected] master -> master (non-fast-forward)

文章目錄


問題

最近用windows,git push總是有一個問題,嫌麻煩,畢竟是自己寫東西玩,直接通過 git push -f ,今天又出現了,煩人~

 ! [rejected]        master     -> master  (non-fast-forward)

追蹤

網上有人說:

git pull origin master --allow-unrelated-histories
git add ...
git commit ...
git push ...

執行git pull origin master --allow-unrelated-histories這句話,把遠程倉庫和本地同步,消除差異
源自:https://blog.csdn.net/xieneng2004/article/details/81044371
但是並沒有解決我的問題。

繼續
git status
在這裏插入圖片描述

自己又git add 嘗試了一次

warning: LF will be replaced by CRLF in .idea/workspace.xml.
The file will have its original line endings in your working directory

有一個警告,一看是警告就知道不處理也行,而這裏提示的.idea/workspace.xml,正是上面報錯得文件

網上查了查,大概意思就是windows的回車和換行符,在提交的時候轉換成換行符,pull代碼的時候再轉換回來
通過git config --global core.autocrlf false可以關閉這個功能,換來換去,什麼鬼?我估計就是換來換去,給我搞壞了
源自:https://www.jianshu.com/p/450cd21b36a4

通過git config core.autocrlf能夠看自己有沒有打開這個功能
在這裏插入圖片描述
果然

別人都只用git pull origin master --allow-unrelated-histories就能解決,但是我還需要改一個這裏git config --global core.autocrlf false,不知道根本原因是不是這個,但是解決問題了,自己也成功push了,就不去糾結原因了。
在這裏插入圖片描述

解決

git pull origin master --allow-unrelated-histories
git config --global core.autocrlf false
git add .
git commit -m ""
git push origin master:master

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章