最近下班回家会学习伯克利的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