最近下班回家會學習伯克利的CS61b課程,其中就有用到git版本管理工具。html
本篇文章是在https://sp18.datastructur.es/materials/guides/using-git.html這篇英文指南基礎上增長本身的理解寫成的,能夠理解爲翻譯加上本身的學習感想。git
1.git版本控制基本操做ide
//建立好須要的文件 這裏咱們在創建了一個新文件夾菜單,其中包括兩類菜:豆腐和肉 $ mkdir tofu $ mkdir meat $ cd meat $ cd ~/desktop/learning/cs61b $ mkdir recipe $ mv meat recipe $ mv tofu recipe $ cd recipe $ ls meat/ tofu/ // 初始化git 62674@zhaodr-workonly MINGW64 ~/desktop/learning/cs61b/recipe $ git init Initialized empty Git repository in C:/Users/62674/Desktop/learning/cs61b/recipe/.git/ //將tofu.TXT加入倉庫 $ git add ./tofu/tofu.txt 62674@zhaodr-workonly MINGW64 ~/desktop/learning/cs61b/recipe (master) $ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: tofu/tofu.txt Untracked files: (use "git add <file>..." to include in what will be committed) meat/
在add 後面可使用status命令查看,發現toufu.txt並無被commit工具
//認可添加並給此次操做附加一個message「add tofu recipe」 $ git commit -m "add tofu recipe" //查看status發現changes to be commited沒有了 $ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) meat/ //log打印日誌,能夠找打commit的代碼 $ git log commit a33651a8d81c92396c662556a39fc512ec66783b (HEAD -> master) Author: zhao <XXXXXXX@qq.com> Date: Sun Apr 8 23:50:15 2018 +0800 add tofu recipe //show顯示詳細內容 $ git show a33651a8d81c92396c662556a39fc512ec66783b commit a33651a8d81c92396c662556a39fc512ec66783b (HEAD -> master) Author: zhao <626742018@qq.com> Date: Sun Apr 8 23:50:15 2018 +0800 add tofu recipe diff --git a/tofu/tofu.txt b/tofu/tofu.txt new file mode 100644 index 0000000..a5bda1a --- /dev/null +++ b/tofu/tofu.txt @@ -0,0 +1,3 @@ +tofu +rice +pepper
當咱們修改了tofu文件之後 查看status會顯示學習
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)ui
modified: tofu/tofu.txtspa
以後咱們繼續重複上述的add commit 操做便可讓倉庫將這一修改添加並保存了翻譯
最後 須要瞭解如何恢復以前的版本:版本控制
//返回上個版本 $ git checkout a33651a8d81c92396c662556a39fc512ec66783b ./tofu //打開tofu.txt發現文件已經變化 //一樣,這個變化也須要commit $ git commit -m "take out bean" //打印log發現checkout並無改變以前的版本信息,只是將重建了一個和以前同樣的文本 $ git log commit 148e66a7ecdea10356cd98456ac9b6d9c091e64e (HEAD -> master) Author: zhao <xxxxx@qq.com> Date: Mon Apr 9 00:07:20 2018 +0800 take out bean commit 64e56f5aed7cdcaba467aa275a933ef0bdc84f1b Author: zhao <xxxxx@qq.com> Date: Mon Apr 9 00:00:32 2018 +0800 add bean commit a33651a8d81c92396c662556a39fc512ec66783b Author: zhao <xxxxx@qq.com> Date: Sun Apr 8 23:50:15 2018 +0800