1. 程式人生 > 其它 >|NO.Z.00010|——————————|^^ 標準 ^^|——|Git&Git私有伺服器部署.V03|--------------------------------------------|IntelliJ IDEA使用Git|

|NO.Z.00010|——————————|^^ 標準 ^^|——|Git&Git私有伺服器部署.V03|--------------------------------------------|IntelliJ IDEA使用Git|



[Development:Git&Git私有伺服器部署.V03]                                                        [Programming.Development] [Git在IntelliJ IDEA中的使用/建立專案並推送到GitHub倉庫/分支管理及分支合併]








一、在IntelliJ IDEA中使用Git:
### --- 在IDEA下建立專案並編寫一個main方法的工程:

~~~     # 在IDEA下新建一個Project
~~~     IDEA——>新建一個Project——>File——>new——>Project :Java:git-test-project——>END
~~~     # 在Project下新建Package
~~~     IDEA——>git-test-project——>src——>右鍵——>New——>Package——>cn.cvc.git——>END

~~~     # 在Package下建立一個class
~~~     IDEA——>git-test-project——>cn.cvc.git——>New——>Java class——>Firestclass——>END
~~~     # 在Firestclass下編寫一個main的方法工程:
### --- 在Firestclass下編寫一個main的方法工程:

package cn.cvc.git;
public class Firestclass {
    public static void main(String[] args){
        System.out.println("Hello git project");
    }
}
二、把git-test-project工程推送到遠端伺服器的版本庫中:
### --- 把git-test-project工程推送到遠端伺服器的版本庫中:

~~~     IDEA——>File——>settings——>Version Control——>Git
~~~     ——>Path to Git executable——>Test——>OK——>END 
三、把編輯的main方法工程檔案新增到Git本地版本庫下:
### --- 把git-test-project工程檔案新增到暫存區
~~~     IDEA——>VCS——>import into Version Control——>Create Git Repository
~~~     ——>git-test-project(在git-test-project的上層目錄java-project建立工作目錄)
~~~     ——>選中:java-project——>OK——>END

~~~     # 在本地找到java-projec目錄下你會發現這兩個檔案.git  git-test-project
~~~     ——>git-test-project本地倉庫建立成功——>END 
~~~     # IDEA中會顯示一個Git的工具窗:
IDEA中會顯示一個Git的工具窗:
### --- 將git-test-project工程檔案提交到本地倉庫

~~~     IDEA——>Git——>對號:commit——>選擇需推送到本地倉庫的檔案
~~~     ——>src\cn\cvc\git\ 1 file    Firestclass.java    git-test-project.iml
~~~     ——>填寫日誌資訊:將IDEA下git-test-project工程檔案推送到本地倉庫——>commit——>END
### --- 修改Firestclass檔案內容再次提交到本地倉庫

~~~     IDEA——>Git——>對號:commit——>修改後的內容對比會顯示出來(圖一)——>commit——>END
~~~     注:main方法執行後,會在git-test-project專案下生成一個out資料夾,此資料夾沒有必要新增到本地倉庫。
四、將git-test-project工程推送到遠端GitHub官方版本庫:
### --- 在GitHub上新建一個版本庫:git-test-project

~~~     IDEA——>Git ——>Push——>master->Define remote:Name:origin    URL:Git官網版本庫地址
~~~     ——>OK——>GitHub使用者名稱:密碼——>Push successful
~~~     ——>在GitHub:git-test-project下檢視工程檔案——>END
### --- 從遠端GitHub官方版本庫克隆專案git-test-project.git

~~~     IDEA——>File——>Close Project——>Get from Version Control——>GitHub
~~~     ——>鍵入GitHub版本庫git-test-project專案工程——>Directory:目標地址
~~~     ——>clone——>在IDEA下檢視clone的專案工程版本——>END 
### --- 修改Firestclass檔案內容並推送到遠端:

~~~     IDEA——>修改Firestclass檔案內容——>commint——>填寫本次日誌:檢查修改的地方內容
~~~     ——>commit——>commit and Push——>Push——>Push successful
~~~     ——>在GitHub遠端倉庫檢視修改後檔案——>END
### --- 在另外一個IDEA上拉取修改後的工程檔案Firestclass:

~~~     IDEA——>Update Project——>OK——>在該專案中檢視修改後的工程檔案——>END
五、在IDEA中如何使用Git的分支與合併:
### --- 建立分支dev並切換分支

~~~     IDEA——>VCS——>Git——>Branches——>New Branch——>檢視當前在哪個分支:dev前有個標籤
~~~     ——>說明當前在dev分支下——>若想切換分支:點選分支:Checkout切換分支——>END
### --- 在dev分支下新建secondclass類檔案:

~~~     IDEA——>Secondclass——>commint——>填寫提交日誌:commint project——>push——>END
### --- 在master分支線新建Thirdclass類檔案:

~~~     IDEA——>切換到master分支——>VCS——>Git——>Branches
~~~     ——>選擇master分支:Checkout——>Thirdclass——>commint
~~~     ——>填寫提交日誌:commint project——>push——>END 
### --- 合併分支:(把dev分支合併到master分支下)

~~~     IDEA——>VCS——>Git——>Branches——>dev:Merge into Current
~~~     ——>在master分支下可以檢視到Secondclass檔案——>dev:delete刪除dev分支
~~~     ——>Push:將工程檔案提交到遠端倉庫——>在遠端倉庫可以檢視到分支合併後的檔案——>END








===============================END===============================


Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart                                                                                                                                                    ——W.S.Landor



來自為知筆記(Wiz)