Git在實際的使用過程中會遇到很多實際問題,下面對這些問題做一一分析和解決。
目錄:
1. no new change問題;
2. unpacker error問題;
3. 中文亂碼(ls -all);
4. 中文亂碼(git status);
1. 推送代碼是出現以下問題:
! [remote rejected] master -> refs/for/master (no new changes)
問題分析:Git bash提示:no new changes表示沒有新的提交。Gerrit根據commit id和changeId判斷是否有新的提交,如果以上兩者都是相同的,則Gerrit會拒絕提交。解決辦法:git commit --amend生成新changeId。
2. 仍然是push代碼時出現的問題:
! [remote rejected] HEAD -> refs/for/k26s/ld/a107c (n/a (unpacker error))
解決辦法:
$ git push --no-thin origin HEAD:refs/for/k26s/ld/a107c
在push指令中,添加參數: --no-thin。
3. Windows平台下使用Git Bash顯示中文出現亂碼。
具體現象如下:
Administrator@ZHANGFENG /f/sptSrcGit/CarDoc (master) $ ls old_document ??????????????????
輸入以下指令即可:
$ alias ls='ls --show-control-chars --color=auto'
4. Windows平台下使用Git Bash時,執行 git status 時顯示中文亂碼問題:
yaya@yaya-PC MINGW64 /d/GitWorkspace/AndroidDemos/HandlerDemo (master)
$ git st
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
"\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt"
nothing added to commit but untracked files present (use "git add" to track)
解決辦法為,輸入如下指令:
git config --global core.quotepath false
5. Windows平台下,提交代碼出現以下提示內容:
yaya@yaya-PC MINGW64 /d/GitWorkspace/OpenSourceProjects (master)
$ git add .
warning: LF will be replaced by CRLF in AndroidIoT/gradlew.
The file will have its original line endings in your working directory.
究其原因:Windows平台下使用回車和換行符(CRLF)作為結束標志,Linux/Mac以換行符作為結束標志(LF)。