天天看點

idea git 整合使用

1、首先在github網站上建立一個repository(如果沒有的話)

  打開https://github.com/

  找到new repository按鈕 輸入repository name 選擇public

  記錄下項目位址:https://github.com/bangbangw/testGit.git

2、打開idea 配置GitHub登入資訊和git本地用戶端資訊

  2.1.配置GitHub登入資訊

  

idea git 整合使用

  2.2.git本地用戶端資訊

idea git 整合使用

3、建立一個項目gitTest01,項目儲存路徑 E:\gitWork\gitTest01

idea git 整合使用

4、項目建立成功後再建立一個git項目庫

idea git 整合使用

  點選 Create Git Repository 之後會提示選擇目錄,這時一定要選擇項目路徑也就是(E:\\gitWork\\gitTest01)

idea git 整合使用

5、将建立好的項目,推送到遠端倉庫(add-->commit-->push)

  (add)将代碼加入到版本庫管理,滑鼠右鍵按照如下選擇

idea git 整合使用

   加入到本地版本庫管理後檔案顔色變化如下:

idea git 整合使用

  (commit)将本地版本庫管理的檔案送出到版本庫

idea git 整合使用

   本地送出完成如下,但是這個時候遠端伺服器還沒有該項目

idea git 整合使用

  (push)将項目送出到遠端伺服器

idea git 整合使用

   第一次送出時,要設定遠端倉庫位址,入下

idea git 整合使用

   點選push送出項目到遠端倉庫

idea git 整合使用

  完美!

6、push時報錯 push to origin/master was rejected錯誤解決方案

idea git 整合使用

  解決方案如下:

  1.切換到自己項目所在的目錄,右鍵選擇GIT BASH Here,Idea中可使用Alt+F12

  2.在terminl視窗中依次輸入指令:

  git pull

  git pull origin master

  git pull origin master --allow-unrelated-histories

  git push -u origin master -f

  搞定,完美!

7、IDEA GIT 忽略檔案最佳方式

   思路:建立一個檔案夾(changelist)類型,然後在送出檔案的時候不要選擇該檔案,具體步驟如下:

  1.建立檔案changelist名為:“noCommit”

idea git 整合使用
idea git 整合使用

  2.送出檔案選擇default,即不要送出“noCommit”這個檔案中的内容,這樣做非常的靈活,如果哪裡一天你要送出忽略的這部分内容,隻需要選擇該檔案夾就可以了

idea git 整合使用
idea git 整合使用