git pull 失敗,解決方案


 

   第1個問題: 解決GIT代碼倉庫不同步

今天在執行git pull時出現:

  1. [root@gitserver /data/work/www/rest/lib/Business/Inventory]# git pull  
  2. Enter passphrase for key '/root/.ssh/id_rsa':  
  3. Updating 70e8b93..a0f1a6c  
  4. error: Your local changes to the following files would be overwritten by merge:  
  5.         rest/lib/Business/Inventory/ProductStatus.php  
  6. Please, commit your changes or stash them before you can merge.  
  7. Aborting 

解決方法:
執行git checkout -f,然后再執行git pull重新checkout

  1. [root@gitserver /data/work/www/rest/lib/Business/Inventory]# git checkout -f  
  2. Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded. 

再執行git pull時就可以了:

  1. [root@gitserver /data/work/www/rest/lib/Business/Inventory]# git pull  
  2. Enter passphrase for key '/root/.ssh/id_rsa':  
  3. Updating 70e8b93..a0f1a6c  
  4. Fast-forward 
  5.  rest/lib/Business/Inventory/ProductStatus.php |    1 +  
  6.  1 files changed, 1 insertions(+), 0 deletions(-)  
  7.  mode change 100644 => 100755 rest/lib/Business/Inventory/ProductStatus.php 

 

第2個問題: git pull的默認地址問題.

1.git處於master這個branch下時,默認的remote就是origin;
2.當在master這個brach下使用指定remote和merge的git pull時,使用默認的remote和merge。
 
但是對於自己建的項目,並用push到遠程服務器上,並沒有這塊內容,需要自己配置。
如果直接運行git pull,會得到如此結果:

#當執行git pull之后的提示:

  1. $ git pull  
  2. Password:  
  3. You asked me to pull without telling me which branch you  
  4. want to merge withand 'branch.master.merge' in 
  5. your configuration file does not tell me, either. Please  
  6. specify which branch you want to use on the command line and 
  7. try again (e.g. 'git pull <repository> <refspec>').  
  8. See git-pull(1) for details.  
  9.    
  10. If you often merge with the same branch, you may want to 
  11. use something like the following in your configuration file:  
  12.    
  13. [branch "master"]  
  14.  remote = <nickname>  
  15.  merge = <remote-ref>  
  16.    
  17. [remote "<nickname>"]  
  18.  url = <url>  
  19.  fetch = <refspec>  
  20.    
  21. See git-config(1) for details. 

#解決方法, 通過git config進行如下配置.

  1. git remote add -f origin git@192.168.21.44:rest.git  
  2. git config branch.master.remote origin  
  3. git config branch.master.merge refs/heads/master 

 

今天經過老大的指點,終於一解困惑我多年的這個問題:

使用git時候,本地新建分支, push到remote上去后,再次pull下來,會報以下提示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
You asked me to pull without telling me which branch you
want to merge with, and 'branch.production.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>' ).
See git-pull(1) for details.
  
If you often merge with the same branch, you may want to
use something like the following in your configuration file :
  
     [branch "production" ]
     remote = <nickname>
     merge = <remote-ref>
  
     [remote "<nickname>" ]
     url = <url>
     fetch = <refspec>
  
See git-config(1) for details.

之前都是按照提示手動配置的,一直在尋找利用口令直接配置的方法,經過老大指點,問題輕松解決:

1
git branch -- set -upstream production origin /production

結果是在項目目錄下 .git/config中添加如下內容,也就是之前我一直手動添加的代碼:

1
2
3
[branch "production" ]
         remote = origin
         merge = refs /heads/production

man git  branch如下:

1
When a local branch is started off a remote-tracking branch, git sets up the branch so that git pull will appropriately merge from the remote-tracking branch. This behavior may be changed via the global branch.autosetupmerge configuration flag. That setting can be overridden by using the --track and --no-track options, and changed later using git branch -- set -upstream.

 

git fetch --all
git reset --hard origin/master
git fetch origin --prune 更新本地分之與遠程同步。
強制覆蓋本地文件


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM