Git版本控制详解

GitHub操作流程:

1.新建代码库

$ git init
$ git clone [url]

2.创建分支

Administrator@UMMMZHE4GX4KT68 MINGW64 ~/Desktop/pythoncode/4.20/my.github.io (master)
$ git checkout -b xxz
Switched to a new branch 'xxz'

3.查看状态

Administrator@UMMMZHE4GX4KT68 MINGW64 ~/Desktop/pythoncode/4.20/my.github.io (xxz)
$ git status
On branch xxz
nothing to commit, working tree clean

注意:这里的master分支变为了xxz

4.对代码进行修改

...这里自行操作...

5.提交到缓存区

git add .   //提交整个文件夹到缓存区
git add xxx  //将修改后的文件提交到缓存区

6.提交到GitHub

git commit -m 'xxx'//添加注释和描述
(git commit -am "注解"addcommit连用)
6.git push origin xxx  //将分支上传到github

7.查看分支、删除分支和切换分支

1.git branch
2.git branch -D xxx  删除本地分支
  git push origin --delete xxx  删除远程分支
3.git checkout xxx

注意:删除分支时需要切换到另外的分支

8.设置全局用户名

1.git config --global user.name "xxz199539"//
2.git config --global user.email "[email protected]"

9.设置公钥

由于没有设置公钥和私钥,再新建项目克隆项目地址时:
$ git clone [email protected]:xxz199539/xxz.github.io.git
Cloning into 'xxz.github.io'...
key_load_public: invalid format
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
这时就需要设置公钥和私钥,通过以下命令实现:
ssh-keygen -t rsa -C 550276107@qq.com
$ ssh-keygen -t rsa -C 550276107@qq.com

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:SK7wvXyTDJ0EhmesI5B8OMjMfple+MxWbmDQ7a1DtjQ 550276107@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|*.. .o.          |
|+B o..*.         |
|..o ==o..        |
| ..=o* E..       |
|  +.*.XoS.       |
|   + B.*o        |
|    + oo..       |
|     . .=        |
|      o. .       |
+----[SHA256]-----+

在/c/Users/Administrator/.ssh文件就能看到一个id_rsa和一个id_rsa.pub文件
获取远程分支,合并分支

git pull origin xxx  获取分支
git merge 合并分支

版本标记

git tag -a 版本号 -m "注解"
 git push origin v4.20
 git tag(查看当前分支)
 git tag -d v4.20删除本地分支
 git push origin --delete tag v4.20删除远程分支


 git show commit-id :查看某次提交的代码
 git log 查看历史版本
 git reset --hard xxx退回到某个id的代码

猜你喜欢

转载自blog.csdn.net/qq_41768400/article/details/80023473