命令名称 | 作用 |
---|---|
git config --global user.name 用户名 | 设置用户签名 |
git config –global user.email 邮箱 | 设置用户邮箱 |
git init | 初始化本地库 |
git status | 查看本地库状态 |
git add 文件名 | 添加到暂存区 |
git commit -m“日志信息” 文件名 | 提交到本地库 |
git reflog | 查看历史记录 |
git reset –hard 版本号 | 版本穿梭 |
1. git config --global user.name 用户名
2. git config --global user.email 邮箱名
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/GitToGitHub (master)
$ cat ~/.gitconfig
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[user]
name = XXX
email = [email protected]
[core]
excludesfile = C:/Users/L/git.ignore
[color]
ui = auto
[http]
sslVerify = false
[https]
sslVerify = false
说明:签名的作用是区分不同操作者身份,用户的签名信息在每一个版本的提交信息中能够看到,以此确认本次提交是谁做的。Git首次安装必须设置一下用户签名,否则无法提交代码。
Note:这里设置用户签名和将来登录GitHub(或者其他代码托管中心)的账号没有任何关系。可以在C盘用户文件夹中的.gitconfi文件中查看配置信息
git init
在windows系统中定位到相应的文件夹资源窗口中,然后右键打开Git Bash就确定了库所在的目录。利用git init命令进行初始化,其目录下会创建.git的隐藏文件夹。
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/GitToGitHub (master)
$ git init
Reinitialized existing Git repository in E:/Git-space/Test/GitToGitHub/.git/
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/GitToGitHub (master)
$ ll -a
total 6
drwxr-xr-x 1 L 197121 0 Jul 24 21:59 ./
drwxr-xr-x 1 L 197121 0 Jul 24 22:07 ../
drwxr-xr-x 1 L 197121 0 Dec 25 18:33 .git/
-rw-r--r-- 1 L 197121 367 Jul 24 21:59 githubURL.txt
-rw-r--r-- 1 L 197121 190 Jul 24 21:59 hello.txt
git status
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ vim hello.txt
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ tail -n 1 hello.txt
11111
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add ..." to include in what will be committed)
hello.txt
nothing added to commit but untracked files present (use "git add" to track)
基本语法:git add 文件名
案例
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git add hello.txt
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached ..." to unstage)
new file: hello.txt
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add ..." to include in what will be committed)
hello.txt
创建的文件还在文件夹中,只是在暂存区中将其删除。
git commit -m”日志信息” 文件名
git reflog
git log
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git commit -m "first commit" hello.txt
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory
[master (root-commit) ad5c7ee] first commit
1 file changed, 1 insertion(+)
create mode 100644 hello.txt
查看一般日志信息
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git reflog
ad5c7ee (HEAD -> master) HEAD@{0}: commit (initial): first commit
查看详细日志信息
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git log
commit ad5c7ee0af3f3d9cb9193da5420102b6cd7dd7e8 (HEAD -> master)
Author: XXX <[email protected]>
Date: Tue Dec 26 10:44:06 2023 +0800
first commit
修改hello.txt文件中的内容,然后通过wim查看。
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ vim hello.txt
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ cat hello.txt
11111
222222
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: hello.txt
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git commit -m "second commit" hello.txt
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory
[master a0bd3a9] second commit
1 file changed, 1 insertion(+)
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git status
On branch master
nothing to commit, working tree clean
1. git reflog 查看版本信息
2. git log 查看版本详细信息
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git reflog
a0bd3a9 (HEAD -> master) HEAD@{0}: commit: second commit
ad5c7ee HEAD@{1}: commit (initial): first commit
1. git reset –-hard 版本号
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git reset --hard ad5c7ee
HEAD is now at ad5c7ee first commit
L@DESKTOP-C3ML9EI MINGW64 /e/Git-space/Test/gitTest (master)
$ git reflog
a0bd3a9 (HEAD -> master) HEAD@{0}: reset: moving to a0bd3a9
ad5c7ee HEAD@{1}: reset: moving to ad5c7ee
a0bd3a9 (HEAD -> master) HEAD@{2}: reset: moving to HEAD
a0bd3a9 (HEAD -> master) HEAD@{3}: commit: second commit
ad5c7ee HEAD@{4}: commit (initial): first commit