Git--创建本地版本库

为了让大家看得更加清晰,我会先简单讲讲每个命令,然后附上具体操作的动态图

本篇博客讲解的git命令

$ git init              //初始化git版本库
$ git status            //查看git仓库当前的状态
$ git add filename      //将工作空间的改变添加到缓存区
$ git commit -m "xxx"   //将缓存区的改变提交到本地仓库
$ git diff              //查看工作区被修改的具体内容
$ cd desktop/testgit              //进入testgit目录
$ pwd                             //列出当前目录路径
/Users/cherish/desktop/testgit
$ ls -a                           //列出当前目录下的所有文件
.   ..  aaa.txt
$ git init
Initialized empty Git repository in /Users/cherish/Desktop/testgit/.git/
$ ls -a
.   ..  .git    aaa.txt
  1. git init初始化当前目录为一个版本库
  2. 初始化后会发现当前目录下多了一个.git文件夹,里面就是存储我们的不同版本的修改以及用户等信息
  3. 在我们客户端对应右键-Team-Share Project,然后选择仓库位置就好了
$ git status
On branch master

Initial commit

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

    aaa.txt

nothing added to commit but untracked files present (use "git add" to track)

git status表示查看当前版本库的状态,下面命令表示:在主分支上,有一个没有追踪的文件,aaa.txt。我们提交一个文件需要两步分别是git addgit commit

$ git add aaa.txt
$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   aaa.txt

$ git commit -m "第一次提交aaa.txt"
[master (root-commit) 7161585] 第一次提交aaa.txt
 1 file changed, 1 insertion(+)
 create mode 100644 aaa.txt
$ git status
On branch master
nothing to commit, working tree clean
  1. 我们首先执行git add aaa.txt,将aaa.txt加入了缓存区,这时执行git status查看状态提示有修改准备被提交
  2. git commit -m "xxx"将缓存区的所有修改文件提交到本地仓库,-m参数后面跟着本次提交的信息,提交完成后显示提交到了主分支,修改了一个文件,在文件中有一行信息改变了
  3. 再次查看状态的时候,会提示工作数是干净的没有进行过修改,没有需要提交的信息
$ vi aaa.txt                       //使用vi编辑器在文件末尾添加了一行1111111
$ git status
On branch master
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:   aaa.txt

no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
diff --git a/aaa.txt b/aaa.txt
index 8ce43a3..0aa23e4 100644
--- a/aaa.txt
+++ b/aaa.txt
@@ -1 +1,2 @@
 test git
+1111111
  1. 使用编辑器在文件末尾添加了一行11111,查看状态时,会提示aaa.txt被修改了
  2. 这个时候可以用git diff查看具体的修改内容,下面显示在test git内容下面增加了一行1111111,➕号表示增加,-号表示删掉
    3.同样使用git addgit commint可以将此次改变提交到版本库
操作截屏:
testgit.gif
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容