git操作常見錯(cuò)誤

轉(zhuǎn)載自:https://blog.csdn.net/dengjianqiang2011/article/details/9260435

2、
如果輸入$ git remote add origin <wbr>git@github.com:djqiang(github帳號(hào)名)/gitdemo(項(xiàng)目名).git <wbr>

<wbr> <wbr> <wbr> <wbr>提示出錯(cuò)信息:fatal: remote origin already exists.

<wbr> <wbr> <wbr> <wbr>解決辦法如下:

<wbr> <wbr> <wbr> <wbr>1、先輸入$ git remote rm origin

<wbr> <wbr> <wbr> <wbr>2、再輸入$ git remote add origin <wbr>git@github.com:djqiang/gitdemo.git <wbr>就不會(huì)報(bào)錯(cuò)了!

<wbr> <wbr> <wbr> <wbr>3、如果輸入$ git remote rm origin <wbr>還是報(bào)錯(cuò)的話,error: Could not remove config section 'remote.origin'. 我們需要修改gitconfig文件的內(nèi)容

<wbr> <wbr> <wbr> 4、找到你的github的安裝路徑,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd<wbr>3358bd96720bb5c8\etc

<wbr> <wbr> <wbr> 5、找到一個(gè)名為gitconfig的文件,打開它把里面的[remote "origin"]那一行刪掉就好了!

3、
Git 提示fatal: remote origin already exists 錯(cuò)誤解決辦法

最后找到解決辦法如下:
1、先刪除遠(yuǎn)程 Git 倉(cāng)庫

$ git remote rm origin

2、再添加遠(yuǎn)程 Git 倉(cāng)庫

$ git remote add origin git@github.com:FBing/java-code-generator

如果執(zhí)行 git remote rm origin 報(bào)錯(cuò)的話,我們可以手動(dòng)修改gitconfig文件的內(nèi)容

$ vi .git/config

這里寫圖片描述

把 [remote “origin”] 那一行刪掉就好了。

4、git push錯(cuò)誤failed to push some refs to
原因:在github上創(chuàng)建的倉(cāng)某個(gè)庫中添加readme文件或者其他什么文件,但是沒有對(duì)本地庫進(jìn)行同步。這個(gè)時(shí)候當(dāng)你再次有commit想要從本地庫提交到遠(yuǎn)程的github庫中時(shí)就會(huì)出現(xiàn)push失敗的問題。
解決辦法:
這個(gè)問題是因?yàn)檫h(yuǎn)程庫與本地庫不一致造成的,那么我們把遠(yuǎn)程庫同步到本地庫就可以了。 使用指令git pull -- rebase origin master
這條指令的意思是把遠(yuǎn)程庫中的更新合并到本地庫中,–rebase的作用是取消掉本地庫中剛剛的commit,并把他們接到更新后的版本庫之中。
5、更新代碼沖突
Your local changes to the following files would be overwritten by merge: ... Please, commit your changes or stash them before you can merge
意思是:更新代碼的時(shí)候出現(xiàn)了代碼沖突。 借鑒自:https://blog.csdn.net/misakaqunianxiatian/article/details/51103734
解決辦法:1、如果希望保留自己所做的改動(dòng),然后更新最新的代碼,再把自己改的代碼提交。可以這樣做
git stash --》 git pull origin master --》 git stash pop
如此一來,服務(wù)器上的代碼更新到了本地,而且你本地修改的代碼也沒有被覆蓋,之后使用add,commit,push 命令即可更新本地代碼到服務(wù)器了。
2、如果希望服務(wù)器上的代碼覆蓋自己改動(dòng)過的代碼:
git reset --hard --》 git pull
5、fatal: Unable to create ‘D:/LearnGit/.git/index.lock’: File exists.
錯(cuò)誤信息為: Another git process seems to be running in this repository, e.g.an editor opened by ‘git commit’. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
解決辦法: https://blog.csdn.net/lihchweb/article/details/74352054
大意如下: 在D盤LearnGit/.git里創(chuàng)建index.lock失?。何募汛嬖?。git的進(jìn)程已經(jīng)在一個(gè)編輯器中被打開。請(qǐng)確保所有的進(jìn)程都結(jié)束,然后再次嘗試。如果仍然失敗,可能是上個(gè)運(yùn)行中的git崩潰,手動(dòng)移除這個(gè)文件。
翻了下.git里的文件,里面有個(gè)index.lock文件。刪除之后再繼續(xù)git操作就沒問題了。
后來了解了下,應(yīng)該是windows對(duì)進(jìn)程的管理有個(gè)上鎖機(jī)制,正常情況下,會(huì)上鎖,進(jìn)程結(jié)束,然后解鎖進(jìn)程。但是由于我強(qiáng)制關(guān)閉了運(yùn)行中的git,導(dǎo)致git崩潰,已經(jīng)上鎖的index.lock沒有來得及解鎖而仍然存在。當(dāng)我再用git add的時(shí)候,git發(fā)現(xiàn)已經(jīng)存在了index.lock這個(gè)文件,導(dǎo)致報(bào)錯(cuò)。
正常情況下 .git 是隱藏文件夾,需要手動(dòng)的設(shè)置顯示隱藏文件方可看到:
window下打開‘我的電腦’,在工具/文件夾選項(xiàng)/查看/里 勾選 顯示隱藏的文件、文件夾或驅(qū)動(dòng)器。然后進(jìn)入文件夾刪除index.lock文件。
或者你可以這樣:命令行里 cd 到該項(xiàng)目的 .git 這個(gè)目錄下, 輸入命令: rm index.lock 即可刪除。
6、 git add . --> git commit -m "xxx" --> git push 出現(xiàn)報(bào)錯(cuò)如下:
error: failed to push some refs to 'http://192.168.10.43/root/creditPro.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.
出錯(cuò)原因:發(fā)現(xiàn)是由于遠(yuǎn)程倉(cāng)庫中代碼版本與本地不一致沖突導(dǎo)致的。
解決辦法:git pull 然后 git push
7、有時(shí)候git pull看不到代碼更新,
原因:也許是沒有切換本地庫到遠(yuǎn)程庫的原因
解決辦法:先git branch查看當(dāng)前代碼所在的分支(是哪個(gè)本地分支還是遠(yuǎn)程哪個(gè)分支) ,然后再git checkout branch branch就是分支的名字,最后再執(zhí)行g(shù)it pull
8、#[git commit 報(bào) "Changes not staged for commit:"
git commit 前沒有 git add .

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容