1、初始化命令:
git init
admin@jimmy MINGW64 /e/Desktop/dbhost
$ git init
Initialized empty Git repository in E:/Desktop/dbhost/.git/
2、检测当前状态命令:
git status
红色:新增/修改
绿色:git已经管理
生成版本
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
leetcode.html
readme.txt
nothing added to commit but untracked files present (use "git add" to track)
3、添加文件:
git add {filename}
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git add leetcode.html
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: leetcode.html
Untracked files:
(use "git add <file>..." to include in what will be committed)
readme.txt
4、添加所有文件:
git add .
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git add .
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: leetcode.html
new file: readme.txt
5、提交加描述:
git commit -m '{decription} '
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git commit -m 'v1'
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'admin@LAPTOP-RO1PQ5JM.(none)')
注意:当创建新项目,git上传提交时出现了如上问题,按照提示操作就可以了。
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git config --global user.email "jimmy@163.com"
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git config --global user.name "jimmy"
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git commit -m 'v1'
[master (root-commit) 76c07ad] v1
2 files changed, 38 insertions(+)
create mode 100644 leetcode.html
create mode 100644 readme.txt
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git status
On branch master
nothing to commit, working tree clean
当文件出现更改后,需要重新提交:
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git add .
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: readme.txt
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git commit -m 'v2'
[master dbaffde] v2
1 file changed, 1 insertion(+)
6、查看版本日志:
git log
admin@jimmy MINGW64 /e/Desktop/dbhost (master)
$ git log
commit dbaffde35dd5eac48c2d505a51350c6bdf656335 (HEAD -> master)
Author: jimmy <jimmy@163.com>
Date: Sun Apr 7 16:13:50 2024 +0800
v2
commit 76c07ad88369073ebf330d040a8c747315bafc20
Author: jimmy <jimmy@163.com>
Date: Sun Apr 7 16:07:54 2024 +0800
v1