##################### 仓库初始化 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo
$ git init
Initialized empty Git repository in G:/git-repo/.git/
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ ll
total 12
drwxr-xr-x 1 47345 197609 0 Jun 29 16:53 ./
drwxr-xr-x 1 47345 197609 0 Jun 29 16:52 ../
drwxr-xr-x 1 47345 197609 0 Jun 29 16:53 .git/
##################### 创建一个a.txt文件 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ touch a.txt
##################### 查看文件修改的状态 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
a.txt
nothing added to commit but untracked files present (use "git add" to track)
##################### 将目录下所有文件加入暂存区 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git add .
##################### 再次查看文件修改的状态 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: a.txt
##################### 提交暂存区到本地仓库 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git commit -m 'adding a.txt to repo'
[master (root-commit) 8b094a6] adding a.txt to repo
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
##################### 对a文件写入些内容 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ vim a.txt
##################### 再次查看文件修改状态 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (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: a.txt
no changes added to commit (use "git add" and/or "git commit -a")
##################### 把修改后的文件添加到暂存区 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git add .
warning: LF will be replaced by CRLF in a.txt.
The file will have its original line endings in your working directory
##################### 再次查看状态 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: a.txt
##################### 提交暂存区到本地仓库 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git commit -m 'update a.txt'
[master 26efdc6] update a.txt
1 file changed, 1 insertion(+)
##################### 查看提交日志 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git log
commit 26efdc650e02e9615660d1bbb2d130c4d5d90619 (HEAD -> master)
Author: “peng” <“473459100@qq.com”>
Date: Wed Jun 29 17:10:29 2022 +0800
update a.txt
commit 8b094a669ace594b10d9be8b965f161b02ba34ac
Author: “peng” <“473459100@qq.com”>
Date: Wed Jun 29 17:05:57 2022 +0800
adding a.txt to repo
##################### 采用别名git-log查看提交日志 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git-log
* 26efdc6 (HEAD -> master) update a.txt
* 8b094a6 adding a.txt to repo
##################### 查看文件内容 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ cat a.txt
i am chinese!
##################### 版本回退 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git reset --hard 8b094a6
HEAD is now at 8b094a6 adding a.txt to repo
##################### 再次查看提交日志 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git-log
* 8b094a6 (HEAD -> master) adding a.txt to repo
##################### 目录下创建git忽略文件 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ touch .gitignore
##################### 目录下创建一个b.a文件 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ touch b.a
##################### 编辑git忽略文件,让git忽略.a文件 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ vi .gitignore
##### 可以看到只有.gitignore文件没有加入到暂存区,a.b没报,被git忽略了 ########
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
nothing added to commit but untracked files present (use "git add" to track)
创建分支、切换分支、合并分支:
##################### master分支中切换到dev01分支 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git checkout dev01
Switched to branch 'dev01'
##################### dev01分支中新建一个dev01.txt ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (dev01)
$ touch dev01.txt
##################### dev01.txt添加 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (dev01)
$ git add .
##################### dev01.txt提交到仓库 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (dev01)
$ git commit -m 'add dev01'
[dev01 b3e84b5] add dev01
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.a
create mode 100644 dev01.txt
##################### 查看日志 ####################
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (dev01)
$ git-log
* b3e84b5 (HEAD -> dev01) add dev01
| * d776e70 (master) add ignore file
|/
* 8b094a6 adding a.txt to repo
##################### 切换到master,观察两个分支的文件目录结构变化 ##############
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (dev01)
$ git checkout master
Switched to branch 'master'
可以发现在dev01中创建的文件,在master中是没有的,可以通过合并两分支解决。
##################### 合并分支前要先切换到master ##############
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (dev01)
$ git checkout master
Switched to branch 'master'
##################### 将dev01分支合并到merge分支 ##############
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git merge dev01
Merge made by the 'ort' strategy.
b.a | 0
dev01.txt | 0
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.a
create mode 100644 dev01.txt
##################### 查看修改日志 ##############
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git-log
* 0fcb629 (HEAD -> master) Merge branch 'dev01'
|\
| * b3e84b5 (dev01) add dev01
* | d776e70 add ignore file
|/
* 8b094a6 adding a.txt to repo
Gitee码云配置:
##################### 生成SSH公钥 ##############
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/47345/.ssh/id_rsa):
/c/Users/47345/.ssh/id_rsa already exists.
Overwrite (y/n)?
##################### 获取公钥,打开这个.pub文件即可 ##############
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDm/UDDewd6/bbywFCZp9TIlmFSdaU6L3/sVTEJ/uWedv2SKpIoMJOUp3Iqnc9668+fQkB6zA7GdHVbCAHJ0st0OhCVvkKKKuB83CG8F7RmizVoDsduQTBRuXLLte4rUJOcd5tH9iOYqniERNYS/bsd47sh/WjlE/aL2ufdjOLZgpUWuG4MjgNFBqxKtkbFBubiAfcmM4svbjxqogriTxkMXMK8DylybikSsVM01nBTo+bsRRJMn1Pay3VfJ1fyMq7bbgRxuuW41VyXWPi/eCE/MkQnHK2iG5tRav4kJ9tevl6Rb+WntBHVeeqdKWU6h0jOhpEcZ5juOMfh3beI7Q+9ngZE2BbVdQA1HM8aa54cuuj/UxKNFUjz57rwrwmEtBZZgjOEc7Zv/zv2VMDF32FvZLdwB4tqWOTpfYw4WxBoaWmB9mu1cbHc8qPHEYIhNxEZKfc196jYnp+bjGnttfE446Vyq32EHzl0oV0RtDe7ovtrCvvdT7GEq6hGyd7JHDM= 47345@DESKTOP-O86FLIS
##################### 验证是否配置成功 ##############
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ ssh -T git@gitee.com
The authenticity of host 'gitee.com (212.64.63.190)' can't be established.
ED25519 key fingerprint is SHA256:+ULzij2u99B9eWYFTw1Q4ErYG/aepHLbu96PAUCoV88.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitee.com' (ED25519) to the list of known hosts.
Hi 阿鹏! You've successfully authenticated, but GITEE.COM does not provide shell access.
##################### 添加远程仓库 ##############
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git remote add origin https://gitee.com/yudongshao/git_test.git
##################### 查看远程仓库 ##############
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git remote
origin
##################### 推送到远程仓库 ##############
47345@DESKTOP-O86FLIS MINGW64 /g/git-repo (master)
$ git push origin master:master
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 4 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (10/10), 805 bytes | 161.00 KiB/s, done.
Total 10 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.3]
To https://gitee.com/yudongshao/git_test.git
* [new branch] master -> master