首先下载git安装软件,安装到本地电脑。
https://git-scm.com/
安装过程一直下一步即可,安装完成后,运行git bash命令工具。
- 查询本地git配置基本配置
$ git config --list
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
rebase.autosquash=true
user.name=chenliang
user.email=chenliang1234576@163.com
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly
remote.origin.url=git@github.com:chenliang1234576/repodemo1.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
- 设置Git的user name和email
git config --global user.name "test"
git config --global user.email "test@test.com"
初始化仓库
Administrator@USER-QKAROI6I4J MINGW64 /c/opt
$ mkdir gitdemo
Administrator@USER-QKAROI6I4J MINGW64 /c/opt
$ cd gitdemo
Administrator@USER-QKAROI6I4J MINGW64 /c/opt/gitdemo
$ git init
Initialized empty Git repository in C:/opt/gitdemo/.git/
Administrator@USER-QKAROI6I4J MINGW64 /c/opt/gitdemo (master)
$ ls -a
./ ../ .git/
- 查看git状态
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
one.txt
nothing added to commit but untracked files present (use "git add" to track)
- 列出git当前目录
$ ll
total 2
-rw-r--r-- 1 Administrator 197121 10 六月 2 05:29 one.txt
-rw-r--r-- 1 Administrator 197121 10 六月 2 05:15 test.txt
- 添加向git缓存区添加文件
$ git add one.txt
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: one.txt
- 提交到本地仓库
$ git commit -m "bash first commit"
[master d66bbee] bash first commit
1 file changed, 1 insertion(+)
create mode 100644 one.txt
- 重置git仓库中的文件到缓存区
$ git reset HEAD one.txt
Unstaged changes after reset:
M one.txt
$ 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: one.txt
no changes added to commit (use "git add" and/or "git commit -a")
- 从缓冲区清除掉最近一次的提交
Administrator@USER-QKAROI6I4J MINGW64 /c/opt/demo2 (master)
$ git checkout -- one.txt
- 查看git最近提交日志记录
$ git log
commit b2f75447e75e3b6ff340f6e571dfe112a28948cd
Author: chenliang <chenliang1234576@163.com>
Date: Sun Jun 2 13:40:06 2019 +0800
test
commit d66bbee1045774d647da4d0831dac24a1340c9dd
Author: chenliang <chenliang1234576@163.com>
Date: Sun Jun 2 13:31:22 2019 +0800
bash first commit
commit b8bb326a25b5642084f4de5222f28f2fabe3da07
Author: chenliang <chenliang1234576@163.com>
Date: Sun Jun 2 13:28:33 2019 +0800
删除
commit a0d6bb5a70a2d3a2dca90839d481ebaa2f2986bd
Author: chenliang <chenliang1234576@163.com>
Date: Sun Jun 2 13:22:43 2019 +0800
one.txt 提交
commit ebcff76939c92ce906e13cc42914d8116a3c3f61
Author: chenliang <chenliang1234576@163.com>
Date: Sun Jun 2 13:16:05 2019 +0800
repo2 first commit
...skipping...
commit d66bbee1045774d647da4d0831dac24a1340c9dd
Author: chenliang <chenliang1234576@163.com>
Date: Sun Jun 2 13:31:22 2019 +0800
bash first commit
commit b8bb326a25b5642084f4de5222f28f2fabe3da07
Author: chenliang <chenliang1234576@163.com>
Date: Sun Jun 2 13:28:33 2019 +0800
删除
commit a0d6bb5a70a2d3a2dca90839d481ebaa2f2986bd
Author: chenliang <chenliang1234576@163.com>
Date: Sun Jun 2 13:22:43 2019 +0800
one.txt 提交
commit ebcff76939c92ce906e13cc42914d8116a3c3f61
Author: chenliang <chenliang1234576@163.com>
Date: Sun Jun 2 13:16:05 2019 +0800
repo2 first commit
重置到 d66bbee1045774d647da4d0831dac24a1340c9dd 版本的仓库信息
$ git reset --hard d66bbee1045774d647da4d0831dac24a1340c9dd
HEAD is now at d66bbee bash first commit
- 删除工作区文件
$ git rm one.txt
rm 'one.txt'
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: one.txt
- 提交删除信息到仓库
$ git commit -m "delete one.txt"
[master 5146d4a] delete one.txt
1 file changed, 1 deletion(-)
delete mode 100644 one.txt
$ git status
On branch master
nothing to commit, working directory clean
网友评论