yhr@VM-24-15-ubuntu:~$ git clone[email protected]:user/repo.git
Cloning into 'repo'...
The authenticity of host 'gitee.com (180.76.199.13)' 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])? ^C
yhr@VM-24-15-ubuntu:~$ mkdir .ssh
yhr@VM-24-15-ubuntu:~$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file inwhich to save the key (/home/yhr/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/yhr/.ssh/id_rsa
Your public key has been saved in /home/yhr/.ssh/id_rsa.pub
The key's randomart image is:
+---[RSA 3072]----+
| |
| |
| |
| |
| . .|
| E S o oo|
| o . *.= ooo|
| . + =oX. . *.+|
| + . . X+ oo O.*.|
|o o.. o.o==+B+= |
+----[SHA256]-----+
注意: 这里没有.ssh 文件,所以我 mkdir .ssh 创建了一个,如果大家 ls 发现有.ssh 文件就可以不用创建!
yhr@VM-24-15-ubuntu:~$ git clone[email protected]:user/repo.git
Cloning into 'repo'...
The authenticity of host 'gitee.com (180.76.199.13)' 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.
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (7/7), done.
Receiving objects: 100% (7/7), done.
remote: Total 7 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
done,成功!
yhr@VM-24-15-ubuntu:~/repo$ git branch * master
yhr@VM-24-15-ubuntu:~/repo$ vim file.txt
yhr@VM-24-15-ubuntu:~/repo$ git add .
yhr@VM-24-15-ubuntu:~/repo$ git commit -m "create file.txt"
[master f066be5] create file.txt
1 file changed, 1 insertion(+)
create mode 100644 file.txt
yhr@VM-24-15-ubuntu:~/repo$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
提交时需要注意,如果我们之前设置过全局的 name 和 email,这两项配置需要和 gitee 上配置的用户名和邮箱一致,否则会出错。或者从来没有设置过全局的 name 和 email,那么我们第一次提交时也会报错。这就需要我们重新配置下了,同样要注意需要和 gitee 上配置的用户名以及邮箱一致。
yhr@VM-24-15-ubuntu:~/repo$ git pull origin master:master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (3/3), 965 bytes | 965.00 KiB/s, done.
From gitee.com:user/repo
f066be5..f779230 master -> master
f066be5..f779230 master -> origin/master
warning: fetch updated the current branch head. fast-forwarding your working tree from commit f066be5ed7f4dc036752e5e1563d9a1f50fe078a.
Already up to date.
yhr@VM-24-15-ubuntu:~/repo$ cat file.txt
hello git
hello world
yhr@VM-24-15-ubuntu:~/repo$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
yhr@VM-24-15-ubuntu:~/repo$ git status
On branch master
Your branch is up to date with 'origin/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)
接下来,我们测试一下 .gitignore 文件的魅力,我们新建 b.so 和 c.so 文件:
yhr@VM-24-15-ubuntu:~/repo$ touch b.so
yhr@VM-24-15-ubuntu:~/repo$ git add -f b.so
yhr@VM-24-15-ubuntu:~/repo$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: .gitignore
new file: b.so
yhr@VM-24-15-ubuntu:~/repo$ vim .gitignore
yhr@VM-24-15-ubuntu:~/repo$ touch c.so
yhr@VM-24-15-ubuntu:~/repo$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: .gitignore
new file: b.so
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: .gitignore
Untracked files:
(use "git add <file>..." to include in what will be committed)
c.so
yhr@VM-24-15-ubuntu:~/repo$ cat .gitignore
#可以直接写文件名
*.ini
*.so
!c.so
检验 .gitignore 的标准就是 git status 命令是不是说 working tree clean。我们发现 Git 并没有提示在工作区有文件新增,那我们的 .gitignore 就生效了。
在我们使用 Git 期间,有些命令敲的时候太长了很麻烦,我们的 git 支持对命令进行简化!比如将 git status 简化为 git st,对应的命令为:
yhr@VM-24-15-ubuntu:~/repo$ git config --global alias.st status
yhr@VM-24-15-ubuntu:~/repo$ git st
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
yhr@VM-24-15-ubuntu:~/repo$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
yhr@VM-24-15-ubuntu:~/repo$ git tag -d v1.0
Deleted tag 'v1.0' (was 602b6fc)
yhr@VM-24-15-ubuntu:~/repo$ git push origin :v1.0
remote: Powered by GITEE.COM [1.1.23]
remote: Set trace flag 4948d598
To gitee.com:user/repo.git
- [deleted] v1.0