Git 学习总结
一. Git 的 三棵树——工作区域,暂存区域,Git仓库
二.Git的工作流程:
1.在工作目录中添加,修改文件
2.将需要进行版本管理的文件放入暂存区域
3.将暂存区域的文件提交到Git仓库
三.Git管理的文件有三种状态:
--已修改(modified)
--已暂存(staged)
--已提交(committed)
四.Linux下的Git操作:
[[email protected] TEST]$ ls -a
. .. fl2440 .git
[[email protected] TEST]$ vim REAMD.md
+ REAMD.md
1 This is a project.
[[email protected] TEST]$ ls
REAMD.md
[[email protected] TEST]$ git add REAMD.md //提交到暂存区域
[master c90ff4f] add a file
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 REAMD.md
[email protected] TEST]$ git status //查看工作状态
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: fl2440/.svn/entries
# deleted: fl2440/.svn/text-base/README.md.svn-base
# deleted: fl2440/README.md
# deleted: fl2440/hello.c
#
no changes added to commit (use "git add" and/or "git commit -a")
[[email protected] TEST]$ git add LICENSE
[[email protected] TEST]$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: LICENSE //显示刚刚提交到暂存区域
#
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
在这里我们学习一个命令: git reset HEAD <file>
功能:将暂存区域的文件撤回
[[email protected] TEST]$ git reset HEAD LICENSE
Unstaged changes after reset:
M fl2440/.svn/entries
M fl2440/.svn/text-base/README.md.svn-base
M fl2440/README.md
M fl2440/hello.c
[[email protected] TEST]$ git status
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: fl2440/.svn/entries
# deleted: fl2440/.svn/text-base/README.md.svn-base
# deleted: fl2440/README.md
# deleted: fl2440/hello.c
#
# Untracked files: //显示未被追踪的文件
# (use "git add <file>..." to include in what will be committed)
#
# LICENSE
# test/
命令:git checkout
例子: git checkout -- LICENSE
功能:上一次提交的暂存区域内容覆盖本地内容 谨慎使用
[[email protected] TEST]$ vim LICENSE //稍微修改了文件内容
文件内容又重新还原了
重新修改再提交
[[email protected] TEST]$ git add LICENSE
[[email protected] TEST]$ git commit -m "change LICENSE"
[master 47ea7e0] change LICENSE
1 files changed, 2 insertions(+), 2 deletions(-)
commit 47ea7e000724cb2dbf895ba47ccdd001e867b789
Date: Tue Apr 24 11:57:53 2018 +0800
change LICENSE
commit 4fd691f5c39060cb6d93b102c6bf1e239448c43b
Date: Tue Apr 24 11:36:11 2018 +0800
add a LICENSE FILE
commit c90ff4fadf3fd34de6f6f3908388b2135e8469ef
Date: Tue Apr 24 10:39:42 2018 +0800
add a file
commit 3b5fdf77bd1887c55ee96a931310abf8a809c066
Date: Sun Apr 22 14:53:22 2018 +0800
Add fl2440 build shell script
回到过去
[[email protected] TEST]$ git reset HEAD~ //回到了上一版本
Unstaged changes after reset:
M LICENSE
M fl2440/.svn/entries
M fl2440/.svn/text-base/README.md.svn-base
M fl2440/README.md
M fl2440/hello.c
[[email protected] TEST]$ git status
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: LICENSE
# deleted: fl2440/.svn/entries
# deleted: fl2440/.svn/text-base/README.md.svn-base
# deleted: fl2440/README.md
# deleted: fl2440/hello.c
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# test/
no changes added to commit (use "git add" and/or "git commit -a")
[[email protected] TEST]$ git log
commit 4fd691f5c39060cb6d93b102c6bf1e239448c43b
Author: huangjunyu <[email protected]>
Date: Tue Apr 24 11:36:11 2018 +0800
add a LICENSE FILE
commit c90ff4fadf3fd34de6f6f3908388b2135e8469ef
Author: huangjunyu <[email protected]>
Date: Tue Apr 24 10:39:42 2018 +0800
add a file
commit 3b5fdf77bd1887c55ee96a931310abf8a809c066
Author: huangjunyu <[email protected]>
Date: Sun Apr 22 14:53:22 2018 +0800
Add fl2440 build shell script