ab168 发表于 2018-9-17 11:04:22

Git小记

  Git简~介
  Git是一个分布式版本控制系统,其他的版本控制系统我只用过SVN,但用的时间不长。大家都知道,分布式的好处多多,而且分布式已经包含了集中式的几乎所有功能。Linus创造Git的传奇经历就不再赘述,直接记录git命令吧!
  文章会尽量按照使用git的顺序来记录,不定时的更新,版面可能会较为杂乱。
  你的计算机上是否有Git?
  windows版本的安装: Git下载 ,下载之后双击安装即可。
  仓库怎么创建?
  仓库(repository),即是一个项目,你要对这个项目进行版本管理。使用如下命令来初始化一个仓库。
creatint@wds MINGW64 /e/Weixin  
$ git init;
  
Initialized empty Git repository in E:/Weixin/.git/
  
creatint@wds MINGW64 /e/Weixin (master)
  文件还需要添加?
  是的,此时虽然建立了仓库,但是其实文件是没有添加进去的,它是空的。
  下面的代码是经常用到的,可以查看当前的文件状态!
creatint@wds MINGW64 /e/Weixin (master)  
$ git status;
  
On branch master
  

  
Initial commit
  

  
Untracked files:
  
(use "git add ..." to include in what will be committed)
  

  
      Common/
  
      Home/
  
      index.php
  
      templates/
  

  
nothing added to commit but untracked files present (use "git add" to track)
  
creatint@wds MINGW64 /e/Weixin (master)
  可以看到没有追踪的文件/文件夹,没有track意味着git没有对它进行管理。你需要添加这些文件(其实是添加到了暂存区,等待下一个命令)。
  怎么提交修改?
  添加文件之后就是提交文件(提交暂存区的文件到工作区)。
creatint@wds MINGW64 /e/Weixin (master)  
$ git add Home;
  查看状态:
creatint@wds MINGW64 /e/Weixin (master)  
$ git status;
  
On branch master
  
Changes to be committed:
  
(use "git reset HEAD ..." to unstage)
  

  
      new file:   .idea/vcs.xml
  
      modified:   Home/index.html
  

  
creatint@wds MINGW64 /e/Weixin (master)
  从上面可以看到,文件Home/index.html已经被修改(追踪,加入到了暂存区),最后再执行提交命令,把此状态添加到当前版本中。
creatint@wds MINGW64 /e/Weixin (master)  
$ git commit -m "修改了标题";
  
On branch master
  
nothing to commit, working directory clean
  
creatint@wds MINGW64 /e/Weixin (master)
  版本怎样穿梭?
  先看看git状态,好像修改了文件?
creatint@wds MINGW64 /e/Weixin (master)  
$ git status;
  
On branch master
  
Changes to be committed:
  
(use "git reset HEAD ..." to unstage)
  

  
      modified:   test.php
  

  
creatint@wds MINGW64 /e/Weixin (master)
  查看一下有什么变化
$ git diff test.php  
diff --git a/test.php b/test.php
  
index 0a02553..790878e 100644
  
--- a/test.php
  
+++ b/test.php
  
@@ -5,4 +5,5 @@
  
* Date: 2016/4/12
  
* Time: 10:51
  
*/
  
-echo 'this is a test.';
  
\ No newline at end of file
  
+echo 'this is a test.';
  
+echo 'hello';
  
\ No newline at end of file
  

  
creatint@wds MINGW64 /e/Weixin (master)
  可以看到,文件增加了一句:echo 'hello';。我们执行add、commit命令后,得到了新的版本。
  版本回退
  我们查看一下此时test.php的代码
$ cat test.php  
页: [1]
查看完整版本: Git小记