Git學習,git學習教程

來源:互聯網
上載者:User

Git學習,git學習教程

Git命令列配置
1 安裝Github
2 安裝msysgit
3 要配置使用者名稱和油箱
  git config --global user.name <使用者名稱>
 我的命令就是:git config --global user.name mchdbagh
  git config --global user.email <油箱>
 我的命令就是:git config --global mchdba@yahoo.com
4 驗證有沒有串連上remote遠程伺服器
ssh -T git@github.com


5 要產生ssh key
$ ssh -keygen
看到需要輸入密碼的,直接2個斷行符號鍵即可回到主視窗。

去找.ssh裡面的id_isa.pub開啟,最好用notepad++開啟,的裡面的內容copy出來,然後放到https://網址裡面,加入
如何產生,請看文檔詳細介紹。http://www.worldhello.net/gotgithub/index.html#id6

Git常用命令介紹
git init --初始化項目,剛開始初始化項目的時候使用
git clone --從伺服器上複製到本地,如果伺服器上面已經有項目了,直接使用這個命令clone到本地進行使用。
git status --查看版本資訊
git add  --添加本地檔案
git commit --提交更改
git push --tags --將更改推送到伺服器


(1) git init操作

[html] view plaincopyprint? 
  1. kyman@SKYMAN-CF7E3587 ~  
  2.  mkdir test_git  
  3.   
  4. kyman@SKYMAN-CF7E3587 ~  
  5.  cd test_git/  
  6.   
  7. kyman@SKYMAN-CF7E3587 ~/test_git  
  8.  ls  
  9.   
  10. kyman@SKYMAN-CF7E3587 ~/test_git  
  11. $ git init  
  12. Initialized empty Git repository in c:/Documents and Settings/skyman/test_git/.git/  
  13.  ls -a  
  14.   ..  .git  


看到有.git檔案

 

[plain] view plaincopyprint? 
  1. $ ls -al  
  2. total 0  
  3. drwxr-xr-x    3 skyman   Administ        0 Sep 25 23:10 .  
  4. drwxr-xr-x   41 skyman   Administ        0 Sep 25 23:10 ..  
  5. drwxr-xr-x    1 skyman   Administ        0 Sep 25 23:10 .git  
  6.   
  7. $  



 

 

看到多另一個.git目錄,表示項目建立成功了。


(2) git clone操作
登陸 https://github.com/,看右下角,,找到開啟庫的網址把提示mchdbagh/manual56加到後面,網址就是https://github.com/mchdbagh/manual56



開啟後,點擊右下角的HTTPS clone URL欄目下方的複製按鈕,就得到了庫的clone地址 https://github.com/mchdbagh/manual56.git,

也可以選擇ssh方式:git@github.com:mchdbagh/manual56.git 

git clone git@github.com:mchdbagh/manual56.git;


開啟 git clone git@github.com:mchdbagh/helloworld.git
如果需要自訂一個目錄名,可以寫成 git clone git@github.com:mchdbagh/helloworld.git test_hw


檢測是否clone成功,看到有manual56目錄是否存在

 

[java] view plaincopyprint? 
  1. $ ls  
  2. AppData           Favorites       NTUSER.DAT  SendTo          _viminfo     manual56                    wc  
  3. Application Data  IECompatCache   NetHood     Templates       admovie.jpg  ntuser.dat.LOG              ??????????????????  
  4. CMB               IETldCache      PrintHood   UserData        client.log   ntuser.ini                  ??????  
  5. Contacts          Local Settings  PrivacIE    VirtualBox VMs  extensions   ntuserdirect_MyManager.dat  
  6. Cookies           My Documents    Recent      WINDOWS         helloworld   test_git  



 

(3) git add 操作實驗

 

[plain] view plaincopyprint? 
  1. $ cd manual56/  
  2. --查看git目前的版本庫的狀態  
  3. $ git status   
  4. # On branch master  
  5. nothing to commit (working directory clean)  
  6.   
  7. --進入我要修改的章節目錄  
  8. $ cd docs/Chapter_17/    
  9. $ vim 17.5.0.0.0.md    --建立一個md檔案,裡面簡單寫“only a test”字串,wq儲存退出編輯狀態。  
  10.   
  11. -- 查看狀態  
  12. $ git status  
  13. # On branch master  
  14. # Untracked files:  
  15. #   (use "git add <file>..." to include in what will be committed)  
  16. #  
  17. #       17.5.0.0.0.md   --看到有紅顏色的一個新的檔案還沒有提交上去,這一行的檔案名稱顯示為紅色。  
  18. nothing added to commit but untracked files present (use "git add" to track)  

 

添加檔案add

git add 17.5.0.0.0.md添加單個檔案,多個檔案可以用空格來隔開,比如(git add 17.5.0.0.0.md 17.5.0.0.1.md 17.5.0.0.2.md),也可以使用git add -A添加所有的檔案。

 

[javascript] view plaincopyprint? 
  1.  --執行添加命令  
  2. $ git add 17.5.0.0.0.md  
  3.   
  4. --查看單個檔案版本狀態  
  5. $ git status 17.5.0.0.0.md   
  6. # On branch master  
  7. # Changes to be committed:  
  8. #   (use "git reset HEAD <file>..." to unstage)  
  9. #  
  10. #       new file:   17.5.0.0.0.md  
  11. #  
  12.   
  13. --查看整個庫版本狀態  
  14. $ git status   
  15. # On branch master  
  16. # Changes to be committed:  
  17. #   (use "git reset HEAD <file>..." to unstage)  
  18. #  
  19. #       new file:   17.5.0.0.0.md  
  20. #  



 

 

手動用MarkdownPad開啟C:\Documents and Settings\skyman\manual56\docs\Chapter_17\17.5.0.0.0.md,在裡面輸入中文字串,儲存退出。然後查看版本庫狀態,顯示綠顏色的表示已經緩衝起來了,顯示紅顏色的是修改過的但是沒有緩衝起來的。

 

[html] view plaincopyprint? 
  1.   

(4) git commit,修改完之後,進行commit提交git commit -m "Test change", -m 是指定提交資訊,必填項目

[html] view plaincopyprint? 
  1. $ git commit -am "Test chanage"  
  2. [master 3e96f90] Test chanage  
  3.  1 file changed, 1 insertion(+), 1 deletion(-)  
  4.    
  5. $ git status   
  6. # On branch master  
  7. # Your branch is ahead of 'origin/master' by 2 commits.  
  8. #  
  9. nothing to commit (working directory clean)  
  10. --顯示已經提交到本地版本庫了  

 

(5)把已經修改的檔案push到伺服器,git push --tags  --push所以緩衝到本機伺服器的檔案。

 

[html] view plaincopyprint? 
  1. $ git push origin master    
  2. Counting objects: 13, done.  
  3. Delta compression using up to 2 threads.  
  4. Compressing objects: 100% (8/8), done.  
  5. Writing objects: 100% (10/10), 768 bytes, done.  
  6. Total 10 (delta 6), reused 0 (delta 0)  
  7. To git@github.com:mchdbagh/manual56.git  
  8.    e754e68..3e96f90  master -> master  



 

 

OK成功了,然後開啟網址https://github.com/xxxxxx/blob/master/docs/Chapter_17/17.5.0.0.0.md去看提交的新內容,見圖片所示,建立立的檔案17.5.0.0.0.md已經成功上傳到remote檔案伺服器了。

 

 

 

這些項目,如果是個人項目,已經足夠滿足我們的日常使用要求了,但是如果多人協同操作,那還是遠遠不夠的。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.