Git安装与基本操作

来源:互联网 发布:postgresql 数据加密 编辑:程序博客网 时间:2024/05/16 02:29

1、安装git

$ sudo apt-get udpate

$ sudo apt-get install git

$ sudo apt-get install git-doc git-svn git-email git-gui gitk


2、绑定用户

用于与GitHub建立联系,直接使用GitHub账户

$ git config --global user.name "stone927"
$ git config --global user.email "787724030@qq.com"

3、创建本地库

$ mkdir GitHome

$ cd GitHome

$ git init


4、添加新文件

$ git add hello.c

$ git commit -m "add hello.c"

(注意:更新文件同样需要这两步操作)


5、查看当前本地库状态

$ 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:   hello.c

no changes added to commit (use "git add" and/or "git commit -a")

6、比较当前文件与版本库的区别

$ git diff hello.c

diff --git a/hello.c b/hello.c
index 41dd832..50aa6ca 100644
--- a/hello.c
+++ b/hello.c
@@ -3,6 +3,6 @@
 int
 main(void)
 {
-       printf("Hello World!\n");
+       printf("Hello World1!\n");
        return 0;
 }

7、查看修改日志

$ git log

commit 10bb9d5f4fae072a119957e517c619010d918fa7
Author: stone <787724030@qq.com>
Date:   Wed Nov 22 17:12:00 2017 +0800

    in hello.c

commit b3f326437969b29f43b82c47d0f937a7c4a2bb3c
Author: stone <787724030@qq.com>
Date:   Wed Nov 22 17:05:46 2017 +0800

    add a file

8、回退版本

$ git reset --hard HEAD^

(说明:有几个'^'表示回退多少个版本,这里表示回退大上一版本)


9、查看远程分支

$ git branch -a


10、查看本地分支

$ git branch


11、创建分支

$ git branch -b myBranch


12、切换到某分支

$ git checkout myBranch


13、删除本地分支

$ git branch -d myBranch







原创粉丝点击