git学习
1.git命令学习
初始化
## 初始化本地库 git init
$ git init
Initialized empty Git repository in F:/devsoft/devsoft/.git/
//.git数据库存储本地库相关的子目录以及文件
-rw-r--r-- 1 l-b-neu 197121 130 6月 13 17:47 config
-rw-r--r-- 1 l-b-neu 197121 73 6月 13 17:47 description
-rw-r--r-- 1 l-b-neu 197121 23 6月 13 17:47 HEAD
drwxr-xr-x 1 l-b-neu 197121 0 6月 13 17:47 hooks/
drwxr-xr-x 1 l-b-neu 197121 0 6月 13 17:47 info/
drwxr-xr-x 1 l-b-neu 197121 0 6月 13 17:47 objects/
drwxr-xr-x 1 l-b-neu 197121 0 6月 13 17:47 refs/
设置签名 git config
#设置全局签名
$ git config --global user.name elite
$ git config --global user.email elite@elite.com
#查看项目级别的签名
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[user]
email = elite@elite.com
name = elite
查看状态 git status
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
git add 添加文件
$ git add goot.txt
warning: LF will be replaced by CRLF in goot.txt.
The file will have its original line endings in your working directory
git commit -m ‘message’ file 提交文件
$ git commit -m 'commit my second ,modified' good.txt
warning: LF will be replaced by CRLF in good.txt.
The file will have its original line endings in your working directory
[master f6ff672] commit my second ,modified
1 file changed, 1 insertion(+)
git log 查看提交的日志
$ git log
commit 4a788b4d0359fd6acafcbf106c7ccc11b5f56692 (HEAD -> master)
Author: elite <elite@elite.com>
Date: Sat Jun 13 19:07:51 2020 +0800
this is third commited;
commit f6ff672d713415e680455e3a0199bdae2109816a
Author: elite <elite@elite.com>
Date: Sat Jun 13 19:01:51 2020 +0800
commit my second ,modified
commit 7b9336df397c8a39e3668754f9552a161e8feae7
Author: elite <elite@elite.com>
Date: Sat Jun 13 18:59:23 2020 +0800
this is my first commited
$ git log --pretty=oneline
$ git log --pretty=oneline
4a788b4d0359fd6acafcbf106c7ccc11b5f56692 (HEAD -> master) this is third commited;
f6ff672d713415e680455e3a0199bdae2109816a commit my second ,modified
7b9336df397c8a39e3668754f9552a161e8feae7 this is my first commited
#查看日志
$ git log --oneline
4a788b4 (HEAD -> master) this is third commited;
f6ff672 commit my second ,modified
7b9336d this is my first commited
$ git reflog
#HEAD当前版本的指针,历史记录的回退和前进
基于索引值操作 $ git reset --hard f6ff672
#回滚到某一个版本
$ git reset --hard f6ff672
HEAD is now at f6ff672 commit my second ,modified
使用^符合,只能往后退
#git reset --hard HEAD^ 回退一步
#git reset --hard HEAD^^^ 回退三步
`使用波浪线回退 ~n 回退n步
$ git reset --hard HEAD ~3
reset三个参数 | 作用 | ||
–soft | 移动本地库head指针 | ||
–hard | 在本地库移动HEAD指针 重置暂存区与工作区 | ||
–mixed | 在本地库移动HEAD指针 重置暂存区 |
rm file 删除文件
git diff 将工作区的文件和暂存区进行比较
$ git diff
diff --git a/hello.txt b/hello.txt
index 4d15aa4..d347dab 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1,3 +1,3 @@
for test delete
-dsds #- 表示原来的内容
+dsds@@@@@ #+表示新增内容
it diff [历史版本】文件名 进行比较
分支管理
#创建分支
git branch 分支名
#查看分支
git branch -v
#切换分支
git checkout 分支名
#合并分支
第一步先切换到master
git merge 分支名
解决冲突
#不同的分支提交了修改的内容
合并出现了冲突
cat 查看冲突的内容
决定去留
git commit -m 'resolve conflict' 提交不需要添加文件名