1. 程式人生 > >解決git pull報錯的方法

解決git pull報錯的方法

2個 password sam branch 報錯 sta posit error: cal

第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 with, and ‘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. If you often merge with the same branch, you may want to
  10. use something like the following in your configuration file:
  11. [branch "master"]
  12. remote = <nickname>
  13. merge = <remote-ref>
  14. [remote "<nickname>"]
  15. url = <url>
  16. fetch = <refspec>
  17. See git-config(1) for details.

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

    1. git remote add -f origin [email protected]:rest.git
    2. git config branch.master.remote origin
    3. git config branch.master.merge refs/heads/master

解決git pull報錯的方法