git pull時出現的常見問題及解決__github

來源:互聯網
上載者:User

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

今天在執行git pull時出現:

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

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

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

再執行git pull時就可以了:

 [root@gitserver /data/work/www/rest/lib/Business/Inventory]# git pull   Enter passphrase for key '/root/.ssh/id_rsa':   Updating 70e8b93..a0f1a6c   Fast-forward   rest/lib/Business/Inventory/ProductStatus.php |    1 +    1 files changed, 1 insertions(+), 0 deletions(-)    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之後的提示:

 $ git pull   Password:   You asked me to pull without telling me which branch you   want to merge with, and 'branch.master.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 "master"]    remote = <nickname>    merge = <remote-ref>       [remote "<nickname>"]    url = <url>    fetch = <refspec>       See git-config(1) for details.  

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

 git remote add -f origin git@192.168.21.44:rest.git   git config branch.master.remote origin   git config branch.master.merge refs/heads/master  本文轉載自:http://ritto.blog.51cto.com/427838/741342

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.