使用Git bash遇到的一些問題解決方法
1.warning: LF will be replaced by CRLF in package.json.(原因是存在符號轉義問題)
The file will have its original line endings in your working directory.
解決:git config --global core.autocrlf true(當 core autocrlf為true時,還有一個需要慎重的地方,當你上傳一個二進制文件,Git可能會將二進制文件誤以為是文本文件,從而也會修改你的二進制文件,從而產生隱患)
2.On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean(其根本原因是版本分支的問題)
3.當 git push origin branch_name時遇到報錯如下:
fatal:'origin' does not appear to be a git repository
fatal:Could not read from remote repository
原因:
本地分支和遠程分支斷開連接
解決方法:
cd 本地分支里
(1)、git branch
——*master 只顯示master
然后查看是否從上游拉了
(2)、git remote –v
——若什么都沒有,則和上游已斷聯系,拉不了代碼也推不了代碼
加關聯
(3)、git remote add origin ssh://git@pandaliusir.github.io(地址)
然后
(4)、git fetch origin
——會顯示下拉的branch情況
再次檢查遠程倉庫,顯示對應的clone地址
git remote –v
——origin git://github.com/schacon/ticgit.git (fetch)
origin git://github.com/schacon/ticgit.git (push)
然后再查分支
git branch –a
——* mater
4.master合並分支時提示“Already up-to-date”
(git pull origin master
From https://github.com/pandaliusir/pandaliusir.github.io
- branch master -> FETCH_HEAD
Already up to date.)
在使用Git把當前分支合並到master提示“Already up-to-date”,但當前分支和 master 分支代碼不同步。假設當前分支是:dev,主分支是:master。
解決方法:
git checkout master;
git reset --hard dev;
git push --force origin master
5.在執行git pull origin master時出現:
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists
解決方案:
git remote add origin git@github:bx_reader/bx-reader-api.git
將關聯遠程倉庫為origin,然后再輸入:
git push -u origin master
就可以提交了
ssh-keygen -t rsa -C “your@email.com”(填寫自己的郵箱地址)回車
接下來會出現:(一路回車就可以)
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
之后打開提示的目錄
C:\Users\liusi.ssh
記事本打開
id_rsa.pub,
復制里面內容
進入自己的賬號https://github.com/settings/keys 點擊 New sshKey,復制的內容粘貼到Key里,標題可以不寫。
驗證:$ ssh -T git@github.com回車
Hi XXXXX! You’ve successfully authenticated, but GitHub does not provide shell access.
成功
6.git將本地內容傳送到遠程倉庫出現![rejected] master -> master (fetch first)錯誤
問題:使用git push -u 遠程庫名 master 命令將本地提交的內容傳到git遠程庫時出現錯誤:
命令: git push -u origin master
出現錯誤:
To https://github.com/imjinghun/university.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/imjinghun/university.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.
解決:git pull --rebase origin master
git push origin master
7.fatal: remote origin already exists.
問題:
git remote add origin https://github.com/lookabc123/lookabc123.github.io.gi
fatal: remote origin already exists.
只要兩步:
1、先刪除
$ git remote rm origin
2、再次執行