概述:
版本控制就是文件跟踪记录的集合,理解每一次记录改变过程
工作目录的每个文件只有两种状态:已跟踪(表示属于git管辖范围)和未跟踪(git未接管范围)
初次克隆都是未修改已跟踪(这里修改是相对于本地)
我们以上次导入的工程为例进行演示如何操作grit,首先需要切换到工程目录下(grit目录下)
1.检查当前文件的状态:
语法:
$ git status这是工程的路径~/表示当前用户下
Administrator@USER-20170424ZG MINGW64 ~/grit (master) $ git status On branch master Your branch is ahead of 'origin/master' by 8 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean 总结:master是我们默认的分支,by 8 commits刚开始修改了提交8次,如果是初次的话这是没有的2.开始新建文件并写入helloWorld字符串
方式一:用 $ echo 'helloWorld' > Hello (就是把‘helloWorld放入Hello文件中’)
方式二:用$ vim Hello, 然后它会弹出文本编辑,按i,输入文字helloWorld , 按Esc(退出编辑模式)按 :wq! (保存退出,注意前面的冒号也是要的)
采用第一种方式:
Administrator@USER-20170424ZG MINGW64 ~/grit (master) $ echo 'helloWorld' > Hello Administrator@USER-20170424ZG MINGW64 ~/grit (master) $ git status On branch master Your branch is ahead of 'origin/master' by 8 commits. (use "git push" to publish your local commits) Untracked files: (use "git add <file>..." to include in what will be committed) Hello nothing added to commit but untracked files present (use "git add" to track) 总结:这时候我们新增加文件是未跟踪,就是还不属于git管辖2.跟踪新文件:
语法:
$ git add 文件名 Administrator@USER-20170424ZG MINGW64 ~/grit (master) $ git add Hello warning: LF will be replaced by CRLF in Hello. The file will have its original line endings in your working directory. Administrator@USER-20170424ZG MINGW64 ~/grit (master) $ git status On branch master Your branch is ahead of 'origin/master' by 8 commits. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: Hello 总结:现在文件变成暂存状态,保存在暂存区3.暂存已修改文件
首先查看我们的文件:
语法:
$ ll total 59 drwxr-xr-x 1 Administrator 197121 0 六月 6 21:41 '~'/ -rw-r--r-- 1 Administrator 197121 2467 六月 6 20:08 API.txt -rw-r--r-- 1 Administrator 197121 2964 六月 6 20:08 benchmarks.rb -rw-r--r-- 1 Administrator 197121 973 六月 6 20:08 benchmarks.txt drwxr-xr-x 1 Administrator 197121 0 六月 6 20:08 examples/ -rw-r--r-- 1 Administrator 197121 3632 六月 6 20:08 grit.gemspec -rw-r--r-- 1 Administrator 197121 11 六月 7 09:22 Hello -rw-r--r-- 1 Administrator 197121 2589 六月 6 21:10 History.txt drwxr-xr-x 1 Administrator 197121 0 六月 6 20:08 lib/ -rw-r--r-- 1 Administrator 197121 1106 六月 6 20:08 LICENSE -rw-r--r-- 1 Administrator 197121 1591 六月 6 20:08 PURE_TODO -rw-r--r-- 1 Administrator 197121 2412 六月 6 20:08 Rakefile -rw-r--r-- 1 Administrator 197121 13 六月 6 21:34 README -rw-r--r-- 1 Administrator 197121 6792 六月 6 20:08 README.md drwxr-xr-x 1 Administrator 197121 0 六月 6 20:08 test/ -rw-r--r-- 1 Administrator 197121 39 六月 6 20:08 VERSION.yml 以修改History.txt 文件为例,保存退出 == 0.7.0 / 2008-01-07 == 0.7.0 / 2008-01-07 Hello World 输入 git status $ vim History.txt Administrator@USER-20170424ZG MINGW64 ~/grit (master) $ git status On branch master Your branch is ahead of 'origin/master' by 8 commits. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: Hello 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) modified: History.txt 将History.txt加入暂存区使用git add History.txt $ git add History.txt Administrator@USER-20170424ZG MINGW64 ~/grit (master) $ git status On branch master Your branch is ahead of 'origin/master' by 8 commits. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: Hello modified: History.txt 4.状态简览 语法 git status -s (s是short的简写) Administrator@USER-20170424ZG MINGW64 ~/grit (master) $ git status -s A Hello M History.txt 总结:A:新增文件 M:修改文件 时间有限,还有一部分下回写