Git本地仓库小白学习。常用命令合集

Git&GitHub
1、版本控制工具应该具备的功能
   协同修改:多人并行不勃的修改服务器端的同一个文件
   数据备份:不仅保存了文件当前状态,还保存了每一个提交的历史状态
   版本管理:不保存重复数据,以节省存储空间,提高运行效率,Git采用文件快照,SVN采用增量式管理
   权限控制:对开发人员进行权限设置,对团队外的开发者的代码进行审核——Git独有
   历史记录:将本地文件恢复到某一个历史状态
   分支管理:允许开发团队在工作过程中多条生产线同时推进任务,进一步提高效率
2、版本控制
   从工程中转换得到的
   集中式版本控制工具容易出现单点故障,分布式版本控制工具则不会。
   Git使用Hash SHA-1来验证文件,从根本性保证数据完整性
Git保存版本机制
  集中式版本控制工具的文件管理机制:以文件变更列表的方式存储信息,这类系统将它们保存的信息看作是一组基本文件和与每个文件随时间逐步积累的差异,有利于节约存储空间
  Git的文件管理机制:Git把数据看作是小型文件系统的一组快照,每次提交更新时Git都会对当前的全部文件制作一个快照并保存这个快照的索引。为了高效,如果文件没有修改,Git将不再重新存储该文件,而是只保留一个链接指向之前存储的文件。所以Git的工作方式可以称之为快照流。
  Git文件管理机制的细节:利用hash值
3、Git优势
   大部分操作在本地完成,不需要联网。SVN则不行
   完整性保证:进行哈希操作
   尽可能添加数据而不是删除或修改数据
   分支操作非常快捷流畅
   与Linux命令全面兼容
4、Git
   三个区域
     工作区:写代码
     暂存区:打算提交还未提交,临时存储
     本地库:历史版本
     本地库——Git add——》暂存区——Git commit——》工作区
6、Git和代码托管中心
代码托管中心就是为了维护远程库
   局域网环境下
      GitLab服务器
   外网环境下
      GitHub
      码云
7、本地库和远程库
   团队内部协作
   跨团队协作


Git命令行操作:
1、本地库操作
 本地库初始化:命令 :Git init ;
             效果:创建出.git隐藏文件夹;
             注意:.Git存放的是本地库相关的子目录和文件,不要删除也不要随意修改
 设置签名:形式 用户名:yyy Email地址:aksj@qq.com 
            作用:区分不同开发人员的身份;
            辨析:这里设置的签名和登录远程库的账号密码不相干
       命令:1、项目级别/仓库级别:仅在当前本地库范围内有效Git config user.name jj_pro  Git config user.email asd@awe.com; 信息保存的位置:./.git/config 文件
	         2、系统用户级别:登录当前操作系统的用户范围 Git config --global jj_glb Git config --global user.email asd@awe.com 信息保存的位置:~/.gitconfig文件
		 级别优先级:就近原则,项目级别优先于系统用户级别,二者都有时采用项目级别的签名
 基本操作
   状态查看操作:git status 查看工作区和暂存区的状态
   添加操作: git add [file name]
   提交操作: git commit -m "提交信息" [file name]
   查看历史记录操作:Git log:全信息,多屏显示的控制方式,空格向下翻页,b向上翻页,q退出
                     Git log --pretty=oneline简洁
		     Git log --oneline更简洁
		     git reflog到某个版本移动到当前版本的步数
   前进后退:本质是基于索引操作
             基于索引值操作:Git reset --hard 索引值
             使用^符号:只能往后退 Git reset --hard HEAD^ 一个^回退一个,n个表示后退n步
	     使用~符号:只能往后退 Git reset --hard HEAD~数字 表示后退数字步
   reset 三个参数的对比
     --hard:在本地库移动head指针,重置暂存区,重置工作区,暂存区变为modify
     --soft:仅仅在本地库移动head指针,暂存区变为modify
     --mixed:在本地库移动head指针,也会重置暂存区
   删除文件并找回
      前提:删除rm 文件名 前,文件存在时的状态提交到了本地库
      操作:Git reset --hard[指针位置]
            删除操作未提交到本地库,指针位置使用HEAD
	    删除操作提交到本地库,指针位置指向历史记录
   比较文件差异
       Git diff[文件名]:将工作区中的文件和暂存区进行比较
       Git different[本地库中历史版本][文件名]:将工作区中的文件和本地库历史记录比较
       不带文件名比较多个文件
 分支管理
   什么是分支?在版本控制的过程中,通过多条线同时推进多个任务 
   分支的好处?同时并行推进多个功能开发,提高开发效率;各个分支在开发过程中,如果某一个分支开发失败不会对其他分支有任何影响。失败的分支删除重新开始即可。
   分支操作
     创建分支:git branch 分支名
     查看分支: git branch -v
     切换分支: git checkout 分支名
     合并分支:1、切换到接收修改分支上(被合并,增加新内容)Git checkout 分支名 2、执行merge命令,Git merge[有新内容分支名]
     解决冲突:冲突的产生,修改了同一文件的相同位置。冲突的表现,在文件内有内容,编辑到满意的内容;冲突的解决:1、编辑文件,删除特殊符号;2、把文件修改到满意的程度,然后保存退出;3、Git add[文件名] 4、git commit -m "日志信息" 注意此时的commit一定不可以带具体文件名。
   分支的管理的实质是在文件管理的基础上利用指针创建和移动指针。
2、远程库操作

具体实操代码及效果


GOD@CS MINGW64 /d/git_learn
$ ll
total 0

GOD@CS MINGW64 /d/git_learn
$ mkdir WeChat

GOD@CS MINGW64 /d/git_learn
$ cd WeChat

GOD@CS MINGW64 /d/git_learn/WeChat
$ ll
total 0

GOD@CS MINGW64 /d/git_learn/WeChat
$ git init
Initialized empty Git repository in D:/git_learn/WeChat/.git/

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ ll
total 0

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ ls -lA
total 4
drwxr-xr-x 1 GOD 197609 0 3月   7 09:23 .git/

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ ll -git
total 0

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ ll .git
total 7
-rw-r--r-- 1 GOD 197609 130 3月   7 09:23 config
-rw-r--r-- 1 GOD 197609  73 3月   7 09:23 description
-rw-r--r-- 1 GOD 197609  23 3月   7 09:23 HEAD
drwxr-xr-x 1 GOD 197609   0 3月   7 09:23 hooks/
drwxr-xr-x 1 GOD 197609   0 3月   7 09:23 info/
drwxr-xr-x 1 GOD 197609   0 3月   7 09:23 objects/
drwxr-xr-x 1 GOD 197609   0 3月   7 09:23 refs/

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git config user.name jjyu

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git config user.email asd@qq.com

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git config --global user.name jjyu2

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git config --global user.email asd2@qq.com

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ vim good.txt

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master

Initial commit

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

        good.txt

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

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git add good.txt

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master

Initial commit

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

        new file:   good.txt


GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git rm --cached good.txt
rm 'good.txt'

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master

Initial commit

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

        good.txt

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

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git add goor.txt
fatal: pathspec 'goor.txt' did not match any files

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git add good.txt

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master

Initial commit

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

        new file:   good.txt


GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git commit good.txt
[master (root-commit) 0142b9b] my first commit new file good.txt
 1 file changed, 7 insertions(+)
 create mode 100644 good.txt

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ cat good.txt
sdasdasd asd
adasd
 asd
 asd
 [mastersjdnasd M )
 qwdijxcjknsa7:wq


GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
nothing to commit, working tree clean

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git status;
On branch master
nothing to commit, working tree clean

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ vim good.txt

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ 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:   good.txt

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

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git add good.txt

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   good.txt


GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ git commit -m "My second commit-motify" good.txt
[master b5212be] My second commit-motify
 1 file changed, 3 insertions(+), 1 deletion(-)

GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ cat good.txt
sdasdasd asd
adasd
 asd
 asd
 [mastersjdnasd M )
 qwdijxcjknsa7:wq
sd
asd
asd:
GOD@CS MINGW64 /d/git_learn/WeChat (master)
$ clear

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git log
commit b5212be558531b9a81795e6d56b8566b4f6941f4
Author: jjyu <asd@qq.com>
Date:   Sat Mar 7 09:57:42 2020 +0800

    My second commit-motify

commit 0142b9b4d9b1b0ffa46112ba1246bb3de98ffdc4
Author: jjyu <asd@qq.com>
Date:   Sat Mar 7 09:49:28 2020 +0800

    my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ vim good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ 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:   good.txt

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

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git add good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   good.txt


GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git commit -m "third commit" good.txt
[master e8208c5] third commit
 1 file changed, 6 insertions(+), 1 deletion(-)

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
nothing to commit, working tree clean

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git log
commit e8208c5babc7cc7f9a9577a35f71d79913bab83e
Author: jjyu <asd@qq.com>
Date:   Sat Mar 7 10:07:11 2020 +0800

    third commit

commit b5212be558531b9a81795e6d56b8566b4f6941f4
Author: jjyu <asd@qq.com>
Date:   Sat Mar 7 09:57:42 2020 +0800

    My second commit-motify

commit 0142b9b4d9b1b0ffa46112ba1246bb3de98ffdc4
Author: jjyu <asd@qq.com>
Date:   Sat Mar 7 09:49:28 2020 +0800

    my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git log --pretty=oneline;
e8208c5babc7cc7f9a9577a35f71d79913bab83e third commit
b5212be558531b9a81795e6d56b8566b4f6941f4 My second commit-motify
0142b9b4d9b1b0ffa46112ba1246bb3de98ffdc4 my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git log --oneline;
e8208c5 third commit
b5212be My second commit-motify
0142b9b my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reflog
e8208c5 HEAD@{0}: commit: third commit
b5212be HEAD@{1}: commit: My second commit-motify
0142b9b HEAD@{2}: commit (initial): my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reflog
0142b9b HEAD@{0}: reset: moving to HEAD~2
e8208c5 HEAD@{1}: reset: moving to e8208c5
b5212be HEAD@{2}: reset: moving to HEAD^
e8208c5 HEAD@{3}: reset: moving to e8208c5
0142b9b HEAD@{4}: reset: moving to 0142b9b
e8208c5 HEAD@{5}: commit: third commit
b5212be HEAD@{6}: commit: My second commit-motify
0142b9b HEAD@{7}: commit (initial): my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reset --hard e8208c5
HEAD is now at e8208c5 third commit

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reset --hard HEAD^^
HEAD is now at 0142b9b my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reset --hard e8208c5
HEAD is now at e8208c5 third commit

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reset --hard HEAD~1
HEAD is now at b5212be My second commit-motify

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ clear

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ Git reflog
b5212be HEAD@{0}: reset: moving to HEAD~1
e8208c5 HEAD@{1}: reset: moving to e8208c5
0142b9b HEAD@{2}: reset: moving to HEAD^^
e8208c5 HEAD@{3}: reset: moving to e8208c5
0142b9b HEAD@{4}: reset: moving to HEAD~2
e8208c5 HEAD@{5}: reset: moving to e8208c5
b5212be HEAD@{6}: reset: moving to HEAD^
e8208c5 HEAD@{7}: reset: moving to e8208c5
0142b9b HEAD@{8}: reset: moving to 0142b9b
e8208c5 HEAD@{9}: commit: third commit
b5212be HEAD@{10}: commit: My second commit-motify
0142b9b HEAD@{11}: commit (initial): my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git log --oneline
b5212be My second commit-motify
0142b9b my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ cat good.txt
sdasdasd asd
adasd
 asd
 asd
 [mastersjdnasd M )
 qwdijxcjknsa7:wq
sd
asd
asd:

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reset --soft e8208c5

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ cat good.txt
sdasdasd asd
adasd
 asd
 asd
 [mastersjdnasd M )
 qwdijxcjknsa7:wq
sd
asd
asd:

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reflog
e8208c5 HEAD@{0}: reset: moving to e8208c5
b5212be HEAD@{1}: reset: moving to HEAD~1
e8208c5 HEAD@{2}: reset: moving to e8208c5
0142b9b HEAD@{3}: reset: moving to HEAD^^
e8208c5 HEAD@{4}: reset: moving to e8208c5
0142b9b HEAD@{5}: reset: moving to HEAD~2
e8208c5 HEAD@{6}: reset: moving to e8208c5
b5212be HEAD@{7}: reset: moving to HEAD^
e8208c5 HEAD@{8}: reset: moving to e8208c5
0142b9b HEAD@{9}: reset: moving to 0142b9b
e8208c5 HEAD@{10}: commit: third commit
b5212be HEAD@{11}: commit: My second commit-motify
0142b9b HEAD@{12}: commit (initial): my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   good.txt


GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reset --mixed 0142b9b
Unstaged changes after reset:
M       good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ 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:   good.txt

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

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reflog
0142b9b HEAD@{0}: reset: moving to 0142b9b
e8208c5 HEAD@{1}: reset: moving to e8208c5
b5212be HEAD@{2}: reset: moving to HEAD~1
e8208c5 HEAD@{3}: reset: moving to e8208c5
0142b9b HEAD@{4}: reset: moving to HEAD^^
e8208c5 HEAD@{5}: reset: moving to e8208c5
0142b9b HEAD@{6}: reset: moving to HEAD~2
e8208c5 HEAD@{7}: reset: moving to e8208c5
b5212be HEAD@{8}: reset: moving to HEAD^
e8208c5 HEAD@{9}: reset: moving to e8208c5
0142b9b HEAD@{10}: reset: moving to 0142b9b
e8208c5 HEAD@{11}: commit: third commit
b5212be HEAD@{12}: commit: My second commit-motify
0142b9b HEAD@{13}: commit (initial): my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reset e8208c5
Unstaged changes after reset:
M       good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reset --hard e8208c5
HEAD is now at e8208c5 third commit

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ vim aaa.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git add aat.txt
fatal: pathspec 'aat.txt' did not match any files

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git add aaa.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git commit -m "new aaa.txt" aaa.txt
[master 627456f] new aaa.txt
 1 file changed, 124 insertions(+)
 create mode 100644 aaa.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
nothing to commit, working tree clean

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ rm aaa.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ ll
total 1
-rw-r--r-- 1 GOD 197609 104 3月   7 10:48 good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    aaa.txt

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

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git add aaa.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    aaa.txt


GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git commit -m "delete aaa.txt" aaa.txt
[master 249a51e] delete aaa.txt
 1 file changed, 124 deletions(-)
 delete mode 100644 aaa.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
nothing to commit, working tree clean

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ ll
total 1
-rw-r--r-- 1 GOD 197609 104 3月   7 10:48 good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reflog
249a51e HEAD@{0}: commit: delete aaa.txt
627456f HEAD@{1}: commit: new aaa.txt
e8208c5 HEAD@{2}: reset: moving to e8208c5
e8208c5 HEAD@{3}: reset: moving to e8208c5
0142b9b HEAD@{4}: reset: moving to 0142b9b
e8208c5 HEAD@{5}: reset: moving to e8208c5
b5212be HEAD@{6}: reset: moving to HEAD~1
e8208c5 HEAD@{7}: reset: moving to e8208c5
0142b9b HEAD@{8}: reset: moving to HEAD^^
e8208c5 HEAD@{9}: reset: moving to e8208c5
0142b9b HEAD@{10}: reset: moving to HEAD~2
e8208c5 HEAD@{11}: reset: moving to e8208c5
b5212be HEAD@{12}: reset: moving to HEAD^
e8208c5 HEAD@{13}: reset: moving to e8208c5
0142b9b HEAD@{14}: reset: moving to 0142b9b
e8208c5 HEAD@{15}: commit: third commit
b5212be HEAD@{16}: commit: My second commit-motify
0142b9b HEAD@{17}: commit (initial): my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reset --hard 627456f
HEAD is now at 627456f new aaa.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ ll
total 5
-rw-r--r-- 1 GOD 197609 1354 3月   7 10:54 aaa.txt
-rw-r--r-- 1 GOD 197609  104 3月   7 10:48 good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ rm bbb.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    bbb.txt

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

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ ll
total 5
-rw-r--r-- 1 GOD 197609 1354 3月   7 10:54 aaa.txt
-rw-r--r-- 1 GOD 197609  104 3月   7 10:48 good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reset --hard HEAD
HEAD is now at e791283 new bbb.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ ll
total 6
-rw-r--r-- 1 GOD 197609 1354 3月   7 10:54 aaa.txt
-rw-r--r-- 1 GOD 197609    5 3月   7 11:01 bbb.txt
-rw-r--r-- 1 GOD 197609  104 3月   7 10:48 good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
nothing to commit, working tree clean

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ ll
total 6
-rw-r--r-- 1 GOD 197609 1354 3月   7 10:54 aaa.txt
-rw-r--r-- 1 GOD 197609    5 3月   7 11:01 bbb.txt
-rw-r--r-- 1 GOD 197609  104 3月   7 10:48 good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
nothing to commit, working tree clean

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ vim bbb.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git diff bbb.txt
diff --git a/bbb.txt b/bbb.txt
index 7be365b..db0d420 100644
--- a/bbb.txt
+++ b/bbb.txt
@@ -1 +1,3 @@
 pple
+as
+as

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git add bbb.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git diff bbb.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git giff head.txt
git: 'giff' is not a git command. See 'git --help'.

Did you mean this?
        diff

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git diff bbb.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git diff head bbb.txt
diff --git a/bbb.txt b/bbb.txt
index 7be365b..db0d420 100644
--- a/bbb.txt
+++ b/bbb.txt
@@ -1 +1,3 @@
 pple
+as
+as

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git diff head^ bbb.txt
diff --git a/bbb.txt b/bbb.txt
new file mode 100644
index 0000000..db0d420
--- /dev/null
+++ b/bbb.txt
@@ -0,0 +1,3 @@
+pple
+as
+as

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ vim good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git diff
diff --git a/good.txt b/good.txt
index a70304d..525b6d0 100644
--- a/good.txt
+++ b/good.txt
@@ -10,5 +10,4 @@ asd
 asd
 GOOD
 GOD
-DOG
-DOG :
+HHHH

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git diff head
diff --git a/bbb.txt b/bbb.txt
index 7be365b..db0d420 100644
--- a/bbb.txt
+++ b/bbb.txt
@@ -1 +1,3 @@
 pple
+as
+as
diff --git a/good.txt b/good.txt
index a70304d..525b6d0 100644
--- a/good.txt
+++ b/good.txt
@@ -10,5 +10,4 @@ asd
 asd
 GOOD
 GOD
-DOG
-DOG :
+HHHH

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   bbb.txt

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:   good.txt


GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reflog
e791283 HEAD@{0}: reset: moving to HEAD
e791283 HEAD@{1}: commit: new bbb.txt
627456f HEAD@{2}: reset: moving to 627456f
249a51e HEAD@{3}: commit: delete aaa.txt
627456f HEAD@{4}: commit: new aaa.txt
e8208c5 HEAD@{5}: reset: moving to e8208c5
e8208c5 HEAD@{6}: reset: moving to e8208c5
0142b9b HEAD@{7}: reset: moving to 0142b9b
e8208c5 HEAD@{8}: reset: moving to e8208c5
b5212be HEAD@{9}: reset: moving to HEAD~1
e8208c5 HEAD@{10}: reset: moving to e8208c5
0142b9b HEAD@{11}: reset: moving to HEAD^^
e8208c5 HEAD@{12}: reset: moving to e8208c5
0142b9b HEAD@{13}: reset: moving to HEAD~2
e8208c5 HEAD@{14}: reset: moving to e8208c5
b5212be HEAD@{15}: reset: moving to HEAD^
e8208c5 HEAD@{16}: reset: moving to e8208c5
0142b9b HEAD@{17}: reset: moving to 0142b9b
e8208c5 HEAD@{18}: commit: third commit
b5212be HEAD@{19}: commit: My second commit-motify
0142b9b HEAD@{20}: commit (initial): my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reset --hardew file good.txt
error: unknown option `hardew'
usage: git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]
   or: git reset [-q] [<tree-ish>] [--] <paths>...
   or: EXPERIMENTAL: git reset [-q] [--stdin [-z]] [<tree-ish>]
   or: git reset --patch [<tree-ish>] [--] [<paths>...]

    -q, --quiet           be quiet, only report errors
    --mixed               reset HEAD and index
    --soft                reset only HEAD
    --hard                reset HEAD, index and working tree
    --merge               reset HEAD, index and working tree
    --keep                reset HEAD but keep local changes
    -p, --patch           select hunks interactively
    -N, --intent-to-add   record only the fact that removed paths will be added later
    -z                    EXPERIMENTAL: paths are separated with NUL character
    --stdin               EXPERIMENTAL: read paths from <stdin>


GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git reset --hard e791283
HEAD is now at e791283 new bbb.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git status
On branch master
nothing to commit, working tree clean

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git branch
* master

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git branch -v
* master e791283 new bbb.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git branch hot_fix

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git branch -v
  hot_fix e791283 new bbb.txt
* master  e791283 new bbb.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git checkout hot_fix
Switched to branch 'hot_fix'

GOD@GNR MINGW64 /d/git_learn/WeChat (hot_fix)
$ git branch -v
* hot_fix e791283 new bbb.txt
  master  e791283 new bbb.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (hot_fix)
$ ll
total 6
-rw-r--r-- 1 GOD 197609 1354 3月   7 10:54 aaa.txt
-rw-r--r-- 1 GOD 197609    5 3月   7 11:44 bbb.txt
-rw-r--r-- 1 GOD 197609  104 3月   7 11:44 good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (hot_fix)
$ vim aaa.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (hot_fix)
$ git status
On branch hot_fix
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")

GOD@GNR MINGW64 /d/git_learn/WeChat (hot_fix)
$ git add aaa.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (hot_fix)
$ git commit aaa.txt
[hot_fix 2b8f5aa]  hot_fix first modify aaa.txt
 1 file changed, 3 insertions(+), 124 deletions(-)
 rewrite aaa.txt (99%)

GOD@GNR MINGW64 /d/git_learn/WeChat (hot_fix)
$ git branch
* hot_fix
  master

GOD@GNR MINGW64 /d/git_learn/WeChat (hot_fix)
$ git branch -v
* hot_fix 2b8f5aa  hot_fix first modify aaa.txt
  master  e791283 new bbb.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (hot_fix)
$ git reflog
2b8f5aa HEAD@{0}: commit: hot_fix first modify aaa.txt
e791283 HEAD@{1}: checkout: moving from master to hot_fix
e791283 HEAD@{2}: reset: moving to e791283
e791283 HEAD@{3}: reset: moving to HEAD
e791283 HEAD@{4}: commit: new bbb.txt
627456f HEAD@{5}: reset: moving to 627456f
249a51e HEAD@{6}: commit: delete aaa.txt
627456f HEAD@{7}: commit: new aaa.txt
e8208c5 HEAD@{8}: reset: moving to e8208c5
e8208c5 HEAD@{9}: reset: moving to e8208c5
0142b9b HEAD@{10}: reset: moving to 0142b9b
e8208c5 HEAD@{11}: reset: moving to e8208c5
b5212be HEAD@{12}: reset: moving to HEAD~1
e8208c5 HEAD@{13}: reset: moving to e8208c5
0142b9b HEAD@{14}: reset: moving to HEAD^^
e8208c5 HEAD@{15}: reset: moving to e8208c5
0142b9b HEAD@{16}: reset: moving to HEAD~2
e8208c5 HEAD@{17}: reset: moving to e8208c5
b5212be HEAD@{18}: reset: moving to HEAD^
e8208c5 HEAD@{19}: reset: moving to e8208c5
0142b9b HEAD@{20}: reset: moving to 0142b9b
e8208c5 HEAD@{21}: commit: third commit
b5212be HEAD@{22}: commit: My second commit-motify
0142b9b HEAD@{23}: commit (initial): my first commit new file good.txt

GOD@GNR MINGW64 /d/git_learn/WeChat (hot_fix)
$ git checkout master
Switched to branch 'master'

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ git merge hot_fix
Updating e791283..2b8f5aa
Fast-forward
 aaa.txt | 123 +---------------------------------------------------------------
 1 file changed, 1 insertion(+), 122 deletions(-)

GOD@GNR MINGW64 /d/git_learn/WeChat (master)
$ cat aaa.txt
123edsa
asd
0000000000
上一篇:给定若干个元素和若干个二元对关系,且关系具有传递性


下一篇:守护线程的概念