Appearance
基本用法
Git 追踪文件使用 git add ,快捷方式为 git add . 。
精细化操作:
- 使用图形界面工具,如 VS Code 。
- 切换到子目录
git add .,只对子目录生效,控制范围。
初始化
初始化仓库,会提醒有分支 master ,自动生成 .git 文件夹。
mkdir mygit
cd mygit
git initUsing 'master' as the name for the initial branch.
This default branch name is subject to change.
To configure the initial branch name to use in all of your new repositories, which will suppress this warning, call:
git config --global init.defaultBranch <name>
Names commonly chosen instead of 'master' are 'main', 'trunk' and 'development'.
The just-created branch can be renamed via this command:
git branch -m <name>
Initialized empty Git repository in ~/mygit/.git/查看状态,会提醒新增文件和使用 git add 命令。
git statusOn branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)新增文件。
echo '# My Git' > README.md
git statusOn branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)加入版本控制。
git add .
git statusOn branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md生成第一个版本。
git commit -m 'init'[master (root-commit) *******] init
1 file changed, 1 insertion(+)
create mode 100644 README.md生成第一个版本时会检查邮箱、用户名,如果没有会提醒配置。
*** 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 defalult identify.
Omit --global to set the identify only in this repository.
fatal: unable to auto-detect email address.查看状态。
git statusOn branch master
nothing to commit, working tree clean查看日志,按 q 退出。
git logcommit ****
Author: Your Name <your.email@abc.com>
Date: **** +0000
init版本
修改文件,加入版本控制,生成版本。
echo 'Hello World' >> README.md
git add .
git commit -m 'insert'[master *******] insert
1 file changed, 1 insertion(+)修改文件,查看差异,生成版本。
echo 'Hello Human' >> README.md
git diffdiff --git a/README.md b/README.md
index *******..******* 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,3 @@
# My Git
Hello World
+Hello Humangit commit -am 'update'[master *******] update
1 file changed, 1 insertion(+)查看版本内容。
git show HEADcommit ****
Author: Your Name <your.email@abc.com>
Date: **** +0000
update
diff --git a/README.md b/README.md
index *******..******* 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,3 @@
# My Git
Hello World
+Hello Human查看上一版本内容。
git show HEAD~1commit ****
Author: Your Name <your.email@abc.com>
Date: **** +0000
insert
diff --git a/README.md b/README.md
index *******..******* 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,2 @@
# My Git
+Hello World搜索日志。
git log --grep='insert'commit ****
Author: Your Name <your.email@abc.com>
Date: **** +0000
insert