1,下载Git

2,安装GIt

3,config :

git config --global user.name "mxb"
git config --global user.email "357670442@qq.com"

4,创建目录并且进行初始化

cd c:
mkdir GitRep
cd c:\GitRep
git init

5,创建readme.txt 并提交

Administrator@Mxb20200114 MINGW64 /c/GitRep (master)
$ git add readme.txt Administrator@Mxb20200114 MINGW64 /c/GitRep (master)
$ git status
On branch master No commits yet Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: readme.txt Administrator@Mxb20200114 MINGW64 /c/GitRep (master)
$ git commit -m "wrote a readme.txt"
[master (root-commit) 654c826] wrote a readme.txt
1 file changed, 2 insertions(+)
create mode 100644 readme.txt Administrator@Mxb20200114 MINGW64 /c/GitRep (master)

6,常用操作:

$ 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") $ git diff readme.txt
diff --git a/readme.txt b/readme.txt
index 3a94755..3c2ffbf 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,3 @@
Git is a version control system.
-Git is free software.
\ No newline at end of file
+Git is free software.
+stupid boss.
\ No newline at end of file

7,查看提交log 和 版本回退

分别是,提交ID,提交的分支名称master,并且当前指针 HEAD 指向 master

提交作者,提交日期.

8,版本回退  git reset –hard  HEAD HEAD^ HEAD~100 分别标识版本号. 或者

git reset –hard 版本号 .将版本库的信息--->工作区.

Administrator@Mxb20200114 MINGW64 /c/GitRep (master)
$ git reset --hard 654c
HEAD is now at 654c826 wrote a readme.txt Administrator@Mxb20200114 MINGW64 /c/GitRep (master)
$ git add readme.txt Administrator@Mxb20200114 MINGW64 /c/GitRep (master)
$ git commit -m "third commit"
[master 4f76d7a] third commit
1 file changed, 2 insertions(+), 1 deletion(-) Administrator@Mxb20200114 MINGW64 /c/GitRep (master)
$ git reflog
4f76d7a (HEAD -> master) HEAD@{0}: commit: third commit
654c826 HEAD@{1}: reset: moving to 654c
949a51f HEAD@{2}: commit: second commit
654c826 HEAD@{3}: commit (initial): wrote a readme.txt Administrator@Mxb20200114 MINGW64 /c/GitRep (master)
$

10,git理论

Git 保存当前库中文件状态 --- add -----> stage  ----   commit  --->  版本库.

uncheck file   -------------取消暂存区.

restore file    -------------将暂存区的文件恢复到工作区

reset –hard 版本号  ------------将版本区的文件恢复到工作区.

GIt   查看命令     git    status  ---查看状态;git diff ---查看区别.

Git  log   查看当前保存的版本号

Git  reflog  查看版本操作.

11,删除文件相关操作

$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) deleted: test.txt no changes added to commit (use "git add" and/or "git commit -a")

12, 创建SSH密钥

12.1 利用命令创建SSH,并且在Administrator文件夹下面找到SSH.PUB

Administrator@Mxb20200114 MINGW64 /c/GitRep (master)
$ ssh-keygen -t rsa -C "357670442@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Created directory '/c/Users/Administrator/.ssh'.
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:fBzUtP87VnN1GcGy8nDxNqgFUf6IXxhimla+nelWi1w 357670442@qq.com
The key's randomart image is:
+---[RSA 3072]----+
| .++....|
| . .o+ o |
| .+oo* o|
| . .*+o*==o|
| S+ooBooo+|
| .. .+.+Eo|
| ..=+ *|
| .+ +.|
| .....|
+----[SHA256]-----+

12.2 在GITHUB里面登陆,并且在Setting –>SSH AND GPG KEYS 里面添加 SSH kEYS.

12.3 将本地仓库GitRep 关联到远程的GitRep

Administrator@Mxb20200114 MINGW64 /c/GitRep (master) $ git remote add origin git@github.com:357670442/GitRep.gitAdministrator@Mxb20200114 MINGW64 /c/GitRep (master) $ git push -u origin master// +u 不仅推送本地分支(版本分支)而且还进行了关联. The authenticity of host 'github.com (13.250.177.223)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts. Enumerating objects: 6, done. Counting objects: 100% (6/6), done. Compressing objects: 100% (4/4), done. Writing objects: 100% (6/6), 475 bytes | 67.00 KiB/s, done. Total 6 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), done. To github.com:357670442/GitRep.git  * [new branch]      master -> master Branch 'master' set up to track remote branch 'master' from 'origin'.

要关联一个远程库,使用命令git remote add origin git@server-name:path/repo-name.git

关联后,使用命令git push -u origin master第一次推送master分支的所有内容;

此后,每次本地提交后,只要有必要,就可以使用命令git push origin master推送最新修改;

13,从远程库克隆

cd c:
$ cd c: Administrator@Mxb20200114 MINGW64 /c
$ git clone git@github.com:357670442/WindowsFormsApp2.git
Cloning into 'WindowsFormsApp2'...
remote: Enumerating objects: 52, done.
remote: Counting objects: 100% (52/52), done.
remote: Compressing objects: 100% (38/38), done.
remote: Total 52 (delta 26), reused 40 (delta 14), pack-reused 0
Receiving objects: 100% (52/52), 27.51 KiB | 163.00 KiB/s, done.
Resolving deltas: 100% (26/26), done.

地址来自于此

14,分支管理

14.1 分支理论

一开始的时候,master分支是一条线,Git用master指向最新的提交,再用HEAD指向master,就能确定当前分支,以及当前分支的提交点:

增加分支后A

此后,每一次提交就变化了B

分支合并C

分支删除D

14.2 实战

Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git checkout -b dev //创建并新建分支.情况A
Switched to a new branch 'dev' Administrator@Mxb20200114 MINGW64 /c/gitrep (dev)
$ git add readme.txt
Administrator@Mxb20200114 MINGW64 /c/gitrep (dev)
$ git commit -m " dev branch"//新的提交 ,情况B
[dev 340b649] dev branch
1 file changed, 2 insertions(+), 1 deletion(-) Administrator@Mxb20200114 MINGW64 /c/gitrep (dev)
$ git checkout master //切换到master分支,并且更改当前工作区内容.
Switched to branch 'master'
Your branch is up to date with 'origin/master'. Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'. nothing to commit, working tree clean Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git checkout dev //更改到分支dev,变化B.
Switched to branch 'dev' Administrator@Mxb20200114 MINGW64 /c/gitrep (dev)
$ git checkout master //切换到master分支,HEAD 指向Master.
Switched to branch 'master'
Your branch is up to date with 'origin/master'. Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git merge dev //将master--超前到dev,合并.master指向dev.
Updating 4f76d7a..340b649
Fast-forward
readme.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-) Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git branch -d dev 删除dev分支.(也就是删除dev指针).
Deleted branch dev (was 340b649). Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git branch //查看当前branch.
* master

Git鼓励大量使用分支:

查看分支:git branch

创建分支:git branch <name>

切换分支:git checkout <name>或者git switch <name>

创建+切换分支:git checkout -b <name>或者git switch -c <name>

合并某分支到当前分支:git merge <name>

删除分支:git branch -d <name>

14.3 Git 合并冲突分支的方法:

Administrator@Mxb20200114 MINGW64 ~
$ cd GitRep
bash: cd: GitRep: No such file or directory Administrator@Mxb20200114 MINGW64 ~
$ cd c:\gitrep Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git branch
feature1
* master Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git branch -d feature1
Deleted branch feature1 (was 4ecc3a5). Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 4 commits.
(use "git push" to publish your local commits) nothing to commit, working tree clean Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git push origin master
Connection reset by 52.74.223.119 port 22
fatal: Could not read from remote repository. Please make sure you have the correct access rights
and the repository exists. Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git push origin master
Enumerating objects: 14, done.
Counting objects: 100% (14/14), done.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (12/12), 1.00 KiB | 205.00 KiB/s, done.
Total 12 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), done.
To github.com:357670442/GitRep.git
4f76d7a..8a0ff69 master -> master Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ $ git log --graph --pretty=oneline --abbrev-commit
bash: $: command not found Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ gitt log --graph
bash: gitt: command not found Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git log --graph
* commit 8a0ff69d95648922252f671adcd3861a28e85f7c (HEAD -> master, origin/master)
|\ Merge: a065329 4ecc3a5
| | Author: mxb <357670442@qq.com>
| | Date: Thu Jan 16 13:08:08 2020 +0800
| |
| | solve conflict
| |
| * commit 4ecc3a51b9b93de7092c54d67e7a52b643e5f804
| | Author: mxb <357670442@qq.com>
| | Date: Thu Jan 16 13:00:32 2020 +0800
| |
| | and simple
| |
* commit 8a0ff69d95648922252f671adcd3861a28e85f7c (HEAD -> master, origin/mast
er)
|\ Merge: a065329 4ecc3a5
| | Author: mxb <357670442@qq.com>
| | Date: Thu Jan 16 13:08:08 2020 +0800
| |
| | solve conflict
| |
| * commit 4ecc3a51b9b93de7092c54d67e7a52b643e5f804
| | Author: mxb <357670442@qq.com>
| | Date: Thu Jan 16 13:00:32 2020 +0800
| |
| | and simple
| |
* commit 8a0ff69d95648922252f671adcd3861a28e85f7c (HEAD -> master, origin/mast
er)
|\ Merge: a065329 4ecc3a5
| | Author: mxb <357670442@qq.com>
| | Date: Thu Jan 16 13:08:08 2020 +0800
| |
| | solve conflict
| |
| * commit 4ecc3a51b9b93de7092c54d67e7a52b643e5f804
| | Author: mxb <357670442@qq.com>
| | Date: Thu Jan 16 13:00:32 2020 +0800
| |
| | and simple
| |
* | commit a065329eafd6ac667bea17148127e9dbd9934be2
|/ Author: mxb <357670442@qq.com>
| Date: Thu Jan 16 13:02:35 2020 +0800
|
| & simple
|
* commit 340b6493a4d0be9f05fa3f8c90b01ca50ed62c5c
| Author: mxb <357670442@qq.com>
| Date: Thu Jan 16 12:48:23 2020 +0800
|
| dev branch
|
* commit 4f76d7a02747fb356b7afca52347eb8687f41331
| Author: mxb <357670442@qq.com>
| Date: Thu Jan 16 09:23:23 2020 +0800
|
| third commit
|
* commit 654c826349e8689059b65b77a4daac76ec98fcd3
Author: mxb <357670442@qq.com>
Date: Thu Jan 16 08:59:47 2020 +0800 wrote a readme.txt Administrator@Mxb20200114 MINGW64 /c/gitrep (master)

Git解决冲突的方法,在回到Master之后,进行Merge,然后其再上一个版本,这个时候,手动进行文件更改,然后

再次进行合并.用git log --graph命令可以看到分支合并图。按q退出.

14.4分支管理策略

使用 $ git merge --no-ff -m "merge with no-ff" dev

新建一个commit,然后进行合并.

删除未合并的分支:

git branch -D <name>强行删除

标签的使用方法

Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git tag v0.9 340b64 Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git tag
v0.9
v1.0 Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git show v0.9
commit 340b6493a4d0be9f05fa3f8c90b01ca50ed62c5c (tag: v0.9)
Author: mxb <357670442@qq.com>
Date: Thu Jan 16 12:48:23 2020 +0800 dev branch diff --git a/readme.txt b/readme.txt
index b3dd77f..1cede17 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,3 +1,4 @@
  1. 命令git tag <tagname>用于新建一个标签,默认为HEAD,也可以指定一个commit id;

  2. 命令git tag -a <tagname> -m "blablabla..."可以指定标签信息;

  3. 命令git tag可以查看所有标签。

  4. 命令 git show <tag> 可以查询信息.

15 码云的使用

注册码云账号,添加SSH,参考前面.然后进行仓库的添加.

Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git remote add gitee_origin https://gitee.com/mao_qin_bin/GitRep.git Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$ git push -u gitee_origin master
Enumerating objects: 18, done.
Counting objects: 100% (18/18), done.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (18/18), 1.38 KiB | 83.00 KiB/s, done.
Total 18 (delta 5), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-3.8]
To https://gitee.com/mao_qin_bin/GitRep.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'gitee_origin'. Administrator@Mxb20200114 MINGW64 /c/gitrep (master)
$

远程的操作:

远程仓库查看  git remote –v

远程慷慨添加 git remote add origin https://gitee.com/mao_qin_bin/GitRep.git

远程仓库删除 git remote rm origin

Git 尝试的更多相关文章

  1. git使用技巧

    git使用技巧 转载自:http://172.17.144.8/iceway.zhang/shares/201604/201604_git_tips.md.html 我们在工作中几乎每天都会用到git ...

  2. Git的撤消操作 - 重置, 签出 和 撤消(转载)

    From:http://gitbook.liuhui998.com/4_9.html http://ihower.tw/blog/archives/2622 相较于SVN这种commit就推送到远端伺 ...

  3. Git Book 中文版 - Git的撤消操作 - 重置, 签出 和 撤消

    Git Book 中文版 - Git的撤消操作 - 重置, 签出 和 撤消 Git的撤消操作 - 重置, 签出 和 撤消 Git提供了多种修复你开发过程中的错误的方法. 方法的选择取决于你的情况: 包 ...

  4. (大数据工程师学习路径)第三步 Git Community Book----中级技能(下)

    一.追踪分支 1.追踪分支 在Git中‘追踪分支’是用于联系本地分支和远程分支的. 如果你在’追踪分支'(Tracking Branches)上执行推送(push)或拉取(pull)时,它会自动推送( ...

  5. git全部使用步骤

    今天要讲的内容:项目管理和工具 Git:版本控制系统 Less:动态的css语言,提高编写CSS的效率 Gulp:项目自动构建工具,对html,css,js,image进行压缩,合并等操作. 一.什么 ...

  6. 7.14 Git 工具 - 凭证存储

    凭证存储 如果你使用的是 SSH 方式连接远端,并且设置了一个没有口令的密钥,这样就可以在不输入用户名和密码的情况下安全地传输数据. 然而,这对 HTTP 协议来说是不可能的 —— 每一个连接都是需要 ...

  7. Git 工具 - 凭证存储

    凭证存储 如果你使用的是 SSH 方式连接远端,并且设置了一个没有口令的密钥,这样就可以在不输入用户名和密码的情况下安全地传输数据. 然而,这对 HTTP 协议来说是不可能的 —— 每一个连接都是需要 ...

  8. 分布式git

    分布式 Git 你现在拥有了一个远程 Git 版本库,能为所有开发者共享代码提供服务,在一个本地工作流程下,你也已经熟悉 了基本 Git 命令.你现在可以学习如何利用 Git 提供的一些分布式工作流程 ...

  9. git用法大全

    转载自实验楼,之前有更新过两篇git的文章,毕竟内容太少,而git还有很多更丰富的技能,在实验楼上有一系列全的教程,这里做一下备案.需要时查阅. Git 实战教程 目录 一.实验说明 二.git的初始 ...

随机推荐

  1. NOIP2018PJ游记

    \(NOIP2018\)普及AFO记 178pt,2=,in ZJ_Hangzhou_学军中学 \(Day\) \(0\) 中午就请假回家打模板了 \(Day\) \(1\) \(A.M.8-12\) ...

  2. 1755: N相关孪生素数

    #include<stdio.h>int f(int n,int L,int R){ int ch[10000],i,j,count=0; j=1; for(i=L;i<=R;i++ ...

  3. 8.HanLP实现--命名实体识别

    笔记转载于GitHub项目:https://github.com/NLP-LOVE/Introduction-NLP 8. 命名实体识别 8.1 概述 命名实体 文本中有一些描述实体的词汇.比如人名. ...

  4. Exchange邮件服务器安全

    Exchange是由微软推出的用于企业环境中部署的邮件服务器.Exchange在逻辑上分为三个层次:网络层(network layer).目录层(directory layer).消息层(messag ...

  5. 牛客练习赛39 C 流星雨 (概率dp)

    题意: 现在一共有n天,第i天如果有流星雨的话,会有wi颗流星雨. 第1天有流星雨的概率是p1. 如果第i−1 (i≥2)天有流星雨,第i天有流星雨的可能性是pi+P,否则是pi. 求n天后,流星雨颗 ...

  6. Python - os.walk()详细使用

    os.walk() 方法简单介绍 主要用来遍历一个目录内各个子目录和子文件 是一个简单易用的文件.目录遍历器,可以帮助我们高效的处理文件.目录方面的事情. 方法参数介绍 os.walk(top[, t ...

  7. pytorch之 bulid_nn_with_2_method

    import torch import torch.nn.functional as F # replace following class code with an easy sequential ...

  8. Angular目录结构

    一. Angular目录结构 e2e:在e2e/下是端到端测试 node_modules:安装的第三方模块都在这,使用npm install安装的1 Src:我们项目的所有文件 { App:组件,以a ...

  9. 1058 - Parallelogram Counting 计算几何

    1058 - Parallelogram Counting There are n distinct points in the plane, given by their integer coord ...

  10. 杭电-------2055An Easy Problem(C语言)

    #include<stdio.h> int main() { int m; int i; scanf("%d", &m); ]; int y; int z; ; ...