五、在IDEA中使用GIt版本控制並將本地代碼上傳至Github


  • 一、安裝git

      Git工具下載:https://git-scm.com/downloads 從官網下載。安裝很簡單,基本都是下一步。

   安裝完的第一件事情就是創建一個Git用戶:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

    還有一個比較重要的命令就是幫助命令:

$ help help
help: help [-dms] [pattern ...]
Display information about builtin commands.

Displays brief summaries of builtin commands. If PATTERN is
specified, gives detailed help on all commands matching PATTERN,
otherwise the list of help topics is printed.

Options:
-d output short description for each topic
-m display usage in pseudo-manpage format
-s output only a short usage synopsis for each topic matching
PATTERN

Arguments:
PATTERN Pattern specifiying a help topic

Exit Status:
Returns success unless PATTERN is not found or an invalid option is given.

  其它也有很多很常用很重要的命令,但我們要在使用的過程中去記憶比較好。

  • 二、創建github賬戶

          gitHub是一個面向開源及私有軟件項目的托管平台,因為只支持git 作為唯一的版本庫格式進行托管,故名gitHub。官方網站:https://github.com/ 

   沒有賬號的話,根據填寫相應的注冊信息,便可以申請一個賬號。對於程序員來說github是一個比較好的工具和網站。

  • 三、在IDEA中配置git

          打開IDEA后 請按照步驟    File -》Settings -》Version Control -》Git -》 Path to Git executable 接下來的看截圖吧!
          

       引入Git的路徑之后,點擊Test,如果可用會彈出如上窗口。

  • 四、IDEA項目引入VCS

  打開IDEA工程項目后, 在菜單欄 VCS-》import  into Version Control -》Create Git Repository -》你的工程目錄。 這樣我們就把idea工程創建了一個Git Repository了,在工程文件目錄下就會多了一個
.git文件夾。這時項目中的文件會變成紅色,表示文件提交到了本地git倉庫當中。
  然后呢?
  

 

 

  • 五、本地 Repositories上傳到Github的 Repositories

   由於本地Git倉庫和Github倉庫之間的傳輸是通過SSH加密的,所以連接時需要設置一下,創建SSH KEY。先看一下你C盤用戶目錄下有沒有.ssh目錄,有的話看下里面有沒有id_rsa和id_rsa.pub這兩個文件,

     有就跳到下一步,沒有就通過下面命令創建:

   ssh-keygen -t rsa -C "youremail@example.com"

  

    

  登錄Github,找到右上角的圖標,打開點進里面的Settings,再選中里面的SSH and GPG KEYS,點擊右上角的New SSH key,然后Title里面隨便填,再把剛才id_rsa.pub里面的內容復制到Title下面的Key內容框里面,

  最后點擊Add SSH key,這樣就完成了SSH Key的加密。具體步驟也可看下面:

       

       

    

  然后自己創建一個倉庫,使用下面紅色字的命令,就可以把本地的庫上傳到github。

…or create a new repository on the command line

 
echo "# C-" >> README.md
git init git add README.md git commit -m "first commit" git remote add origin https://github.com/zhuguangjin/C-.git git push -u origin master 

…or push an existing repository from the command line

 
git remote add origin https://github.com/zhuguangjin/C-.git git push -u origin master

…or import code from another repository

You can initialize this repository with code from a Subversion, Mercurial, or TFS project.

 


免責聲明!

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



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