Git
1. 现有项目开发中存在的问题
- 项目的安全性没有保证
- 不能做版本回退
- 无法快速进行协同开发
- 版本备份过多,导致混乱。
2.Git是什么
git是一个分布式版本控制及协同开发工具。
版本控制工具分类
-
集中式版本控制工具 SVN
-
分布式版本控制工具 Git
3.git安装
-
运行安装包
-
打开git bash
-
自报家门
$ git config --global user.name "Your Name" #MBY $ git config --global user.email "email@example.com" #957....
补充一:
shell命令:
$ cd d:/
$ ll
$ clear
$ cd testgit #仓库
$ git init
Initialized empty Git repository in D:/testgit/.git/ #Initialized empty Git repository in D:/testgit/.git/ #版本库
D:\testgit下新建:a.txt
$ git add a.txt #交给git管理 --- 提交给版本库
$ git commit -m "v1.0" #设置版本 --- 提交给版本库(每次提交一次生成一个版本)
[master (root-commit) 96dc0ac] v1.0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
$ git diff a.txt #查看文件修改了哪些内容 ---- 坑
$ git diff a.txt
diff --git a/a.txt b/a.txt
index e69de29..7e4f22a 100644
--- a/a.txt
+++ b/a.txt
@@ -0,0 +1 @@
+2update v3.0
\ No newline at end of file
#########注意:06:41
$ git status
On branch master
nothing to commit, working tree clean
// git的使用
// 自己的笔记
// 复习
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: a.txt
no changes added to commit (use "git add" and/or "git commit -a")
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ ^C
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git add a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git commit -m "v3.0"
[master 1d15ae4] v3.0
1 file changed, 3 insertions(+)
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
nothing to commit, working tree clean
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git diff a.txt #查看文件中修改了哪些内容
diff --git a/a.txt b/a.txt
index 0bcf855..5f88af6 100644
--- a/a.txt
+++ b/a.txt
@@ -1,3 +1,3 @@
1update v2.0
-2update v3.0
+2update v3.0 + 0.1 v3.1
3update v4.0
\ No newline at end of file
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git add a.txt # 将文件添加到暂存区
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status #查看仓库的状态。如果工作区有修改,呈现出红色。若果将修改添加到暂存区,呈现出绿色。
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git diff a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git commit -m "v3.1" #将暂存区的文件添加到主干分支
[master 366a213] v3.1
1 file changed, 1 insertion(+), 1 deletion(-)
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: a.txt
no changes added to commit (use "git add" and/or "git commit -a")
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git diff a.txt #查看文件中修改了哪些内容。(注意:在没有add之前。眼神好 使)
diff --git a/a.txt b/a.txt
index 5f88af6..10453b3 100644
--- a/a.txt
+++ b/a.txt
@@ -1,3 +1,3 @@
-1update v2.0
+1update version v2.0
2update v3.0 + 0.1 v3.1
3update v4.0
\ No newline at end of file
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status #查看仓库的状态。如果工作区有修改,呈现出红色。若果将修改添加到暂存区,呈现出绿色。
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: a.txt
no changes added to commit (use "git add" and/or "git commit -a")
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git add a.txt #将文件添加到暂存区
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git commit -m "v4.0" #将暂存区的文件提交到主干分支。
[master 10892ed] v4..0
1 file changed, 1 insertion(+), 1 deletion(-)
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status #查看仓库的状态。如果工作区有修改,呈现出红色。若果将修改添加到暂存区,呈现出绿色。
On branch master
nothing to commit, working tree clean
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git log #查看当前版本及当前版本之前的版本。
commit 10892ed338f316a637d944d1b83226eb159231ce (HEAD -> master)
Author: MBY <957935694@qq.com>
Date: Sun Dec 22 14:59:18 2019 +0800
v4..0
commit 366a2135c02eb0dd0371ed677d31474223b0b75e
Author: MBY <957935694@qq.com>
Date: Sun Dec 22 14:34:01 2019 +0800
v3.1
commit 1d15ae4a69642dbd2b17223c3a2d803159cf9151
Author: MBY <957935694@qq.com>
Date: Sun Dec 22 14:21:02 2019 +0800
v3.0
commit 96dc0ac254c2408e40cfed8d3954d2b7f5b1dbcb
Author: MBY <957935694@qq.com>
Date: Mon Nov 4 12:43:12 2019 +0800
v1.0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git log --pretty=oneline
10892ed338f316a637d944d1b83226eb159231ce (HEAD -> master) v4..0 #当前的指针在哪
366a2135c02eb0dd0371ed677d31474223b0b75e v3.1
1d15ae4a69642dbd2b17223c3a2d803159cf9151 v3.0
96dc0ac254c2408e40cfed8d3954d2b7f5b1dbcb v1.0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git reset --hard HEAD^ #回到哪个版本
HEAD is now at 366a213 v3.1
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git log --pretty=oneline
366a2135c02eb0dd0371ed677d31474223b0b75e (HEAD -> master) v3.1 #当前的指针在哪
1d15ae4a69642dbd2b17223c3a2d803159cf9151 v3.0
96dc0ac254c2408e40cfed8d3954d2b7f5b1dbcb v1.0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git reset --hard 10892ed338f316a637d944d1b83226eb159231ce #回到哪个版本
HEAD is now at 10892ed v4..0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git log --pretty=oneline
10892ed338f316a637d944d1b83226eb159231ce (HEAD -> master) v4..0
366a2135c02eb0dd0371ed677d31474223b0b75e v3.1
1d15ae4a69642dbd2b17223c3a2d803159cf9151 v3.0
96dc0ac254c2408e40cfed8d3954d2b7f5b1dbcb v1.0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git log --pretty=oneline
10892ed338f316a637d944d1b83226eb159231ce (HEAD -> master) v4..0
366a2135c02eb0dd0371ed677d31474223b0b75e v3.1
1d15ae4a69642dbd2b17223c3a2d803159cf9151 v3.0
96dc0ac254c2408e40cfed8d3954d2b7f5b1dbcb v1.0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git reset --hard HEAD^
HEAD is now at 366a213 v3.1
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git log --pretty=oneline
366a2135c02eb0dd0371ed677d31474223b0b75e (HEAD -> master) v3.1
1d15ae4a69642dbd2b17223c3a2d803159cf9151 v3.0
96dc0ac254c2408e40cfed8d3954d2b7f5b1dbcb v1.0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ clear
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git reflog #查看版本库中所有版本
366a213 (HEAD -> master) HEAD@{0}: reset: moving to HEAD^
10892ed HEAD@{1}: reset: moving to 10892ed338f316a637d944d1b83226eb159231ce
366a213 (HEAD -> master) HEAD@{2}: reset: moving to HEAD^
10892ed HEAD@{3}: commit: v4..0
366a213 (HEAD -> master) HEAD@{4}: commit: v3.1
1d15ae4 HEAD@{5}: commit: v3.0
96dc0ac HEAD@{6}: commit (initial): v1.0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git reset --hard 10892ed
HEAD is now at 10892ed v4..0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git log
commit 10892ed338f316a637d944d1b83226eb159231ce (HEAD -> master)
Author: MBY <957935694@qq.com>
Date: Sun Dec 22 14:59:18 2019 +0800
v4..0
commit 366a2135c02eb0dd0371ed677d31474223b0b75e
Author: MBY <957935694@qq.com>
Date: Sun Dec 22 14:34:01 2019 +0800
v3.1
commit 1d15ae4a69642dbd2b17223c3a2d803159cf9151
Author: MBY <957935694@qq.com>
Date: Sun Dec 22 14:21:02 2019 +0800
v3.0
commit 96dc0ac254c2408e40cfed8d3954d2b7f5b1dbcb
Author: MBY <957935694@qq.com>
Date: Mon Nov 4 12:43:12 2019 +0800
v1.0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: a.txt
no changes added to commit (use "git add" and/or "git commit -a")
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git add a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: a.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
b.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git commit -m "v5.0"
[master 8150b3e] v5.0
1 file changed, 2 insertions(+), 1 deletion(-)
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status #git管理的是修改而不是文件
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
b.txt
nothing added to commit but untracked files present (use "git add" to track)
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: a.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
b.txt
no changes added to commit (use "git add" and/or "git commit -a")
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ cat a.txt
1update version v2.0
2update v3.0 + 0.1 v3.1
3update v4.0
4 update v5.0
My stupid boss still perfers SVN.
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git checkout a.txt #将工作区的修改撤销掉
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ cat a.txt
1update version v2.0
2update v3.0 + 0.1 v3.1
3update v4.0
4 update v5.0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: a.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
b.txt
no changes added to commit (use "git add" and/or "git commit -a")
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git add a.txt #添加到寄存区
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: a.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
b.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git reset HEAD a.txt
Unstaged changes after reset:
M a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: a.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
b.txt
no changes added to commit (use "git add" and/or "git commit -a"
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ cat a.txt
1update version v2.0
2update v3.0 + 0.1 v3.1
3update v4.0
4 update v5.0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ cat a.txt
1update version v2.0
2update v3.0 + 0.1 v3.1
3update v4.0
4 update v5.0
My stupid boss still prefers SVN.
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git checkout a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ cat a.txt
1update version v2.0
2update v3.0 + 0.1 v3.1
3update v4.0
4 update v5.0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
b.txt
nothing added to commit but untracked files present (use "git add" to track)
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git add b.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: b.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git commit -m "vb11.0"
[master d2f5e92] vb11.0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ ll
total 1
-rw-r--r-- 1 lenovo 197121 74 12月 22 16:13 a.txt
-rw-r--r-- 1 lenovo 197121 0 12月 22 15:54 b.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ rm b.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ ll
total 1
-rw-r--r-- 1 lenovo 197121 74 12月 22 16:13 a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ 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: b.txt #testgit中也没有了
no changes added to commit (use "git add" and/or "git commit -a")
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git rm b.txt
rm 'b.txt'
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: b.txt #绿色
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git commit -m "del b.txt"
[master e0dc012] del b.txt
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 b.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git status
On branch master
nothing to commit, working tree clean
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ ll
total 1
-rw-r--r-- 1 lenovo 197121 74 12月 22 16:13 a.txt
4.git的使用
-
先找一个看起来舒服的文件夹,进入这个文件夹。执行git init 命令
1.git add 文件名 ----------------------将文件添加到暂存区 2.git commit -m "信息" -------------------将暂存区的文件提交到主干分支。 3.git status -------------------------查看仓库的状态。如果工作区有修改,呈现出红色。如果将修改添 加到暂存区,呈现出绿色。 4.git diff 文件名 --------------------查看文件中修改了哪些内容。(注意:在没有add之前。眼神好 使) 5.git log ----------------------------查看当前版本及当前版本之前的版本。 6.git reset --hard 版本号 -------------回到哪个版本 7.git reflog -------------------------查看版本库中所有版本。 8.git checkout -- 文件名 --------------将工作区的修改撤销掉 9.git reset HEAD 文件名 ---------------将暂存区的修改撤回到工作区 10.git rm 文件名 ---------------------将删除的修改操作添加到暂存区
5.git的仓库,工作区,暂存区,主干分支
6.远程仓库 GitHub
// 复习
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ ssh-keygen -t rsa -C "957935694@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/lenovo/.ssh/id_rsa):
Created directory '/c/Users/lenovo/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/lenovo/.ssh/id_rsa.
Your public key has been saved in /c/Users/lenovo/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:X+68HyE36TzWQIHihG8ZxqY/BH4LSbQL9fB4VQ77BbY 957935694@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| .+o oo= |
| .+*B..= + |
| .ooX++. E .|
| .=oB o o |
| S* .o B |
| .+o = = |
| ... * .|
| o . o |
| +o. |
+----[SHA256]-----+
C:\Users\lenovo\.ssh
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git clone https://github.com/githubmaby/160test.git
Cloning into '160test'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ ll
total 1
drwxr-xr-x 1 lenovo 197121 0 12月 22 17:36 160test/ #克隆成功
-rw-r--r-- 1 lenovo 197121 74 12月 22 16:13 a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ cd ..
lenovo@LAPTOP-SNB6RGPG MINGW64 /d
$ git clone https://github.com/githubmaby/160test.git
Cloning into '160test'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
lenovo@LAPTOP-SNB6RGPG MINGW64 /d
$ ll
total 52035
drwxr-xr-x 1 lenovo 197121 0 7月 22 2017 '$RECYCLE.BIN'/
-rw-r--r-- 1 lenovo 197121 53 11月 9 15:52 1.csv
drwxr-xr-x 1 lenovo 197121 0 12月 22 17:39 160test/ #克隆成功
drwxr-xr-x 1 lenovo 197121 0 5月 5 2019 3000soft/
drwxr-xr-x 1 lenovo 197121 0 9月 18 13:23 360极速浏览器下载/
drwxr-xr-x 1 lenovo 197121 0 10月 23 16:39 7-Zip/
-rw-r--r-- 1 lenovo 197121 4096 10月 25 13:46 a.xls
drwxr-xr-x 1 lenovo 197121 0 8月 19 14:38 apache-maven-3.6.1/
drwxr-xr-x 1 lenovo 197121 0 12月 12 19:34 apache-storm-2.0.0/
drwxr-xr-x 1 lenovo 197121 0 8月 13 08:51 apache-tomcat-6.0.36/
drwxr-xr-x 1 lenovo 197121 0 8月 21 10:29 apache-tomcat-8.5.30/
-rw-r--r-- 1 lenovo 197121 4608 10月 25 13:52 b.xls
drwxr-xr-x 1 lenovo 197121 0 3月 8 2019 BaiduNetdiskDownload/
drwxr-xr-x 1 lenovo 197121 0 1月 4 2018 baiduyudisk/
drwxr-xr-x 1 lenovo 197121 0 10月 25 21:53 CentOS_Hadoop1/
drwxr-xr-x 1 lenovo 197121 0 12月 1 21:42 CentOS_Hadoop3/
drwxr-xr-x 1 lenovo 197121 0 12月 16 21:32 checkpoint01/
-rw-r--r-- 1 lenovo 197121 52938000 10月 28 11:14 clean_access.tmp2019-05-19-10 -28.log
drwxr-xr-x 1 lenovo 197121 0 10月 6 19:16 client/
drwxr-xr-x 1 lenovo 197121 0 11月 3 00:30 Config.Msi/
drwxr-xr-x 1 lenovo 197121 0 6月 14 2019 default/
drwxr-xr-x 1 lenovo 197121 0 11月 24 11:09 demo/
drwxr-xr-x 1 lenovo 197121 0 10月 2 22:31 Documents/
drwxr-xr-x 1 lenovo 197121 0 5月 27 2017 Drivers/
-rw-r--r-- 1 lenovo 197121 5120 10月 25 15:10 easy.xls
-rw-r--r-- 1 lenovo 197121 6144 10月 25 15:13 easy1.xls
drwxr-xr-x 1 lenovo 197121 0 12月 17 13:17 eval/
drwxr-xr-x 1 lenovo 197121 0 11月 4 09:24 Git/
drwxr-xr-x 1 lenovo 197121 0 10月 24 20:20 Hadoop/
-rw-r--r-- 1 lenovo 197121 614 11月 15 11:39 'Hello$.class'
-rw-r--r-- 1 lenovo 197121 555 11月 15 11:39 Hello.class
-rw-r--r-- 1 lenovo 197121 78 11月 15 11:38 Hello.scala
drwxr-xr-x 1 lenovo 197121 0 10月 30 18:49 home/
drwxr-xr-x 1 lenovo 197121 0 9月 9 12:43 'IntelliJ IDEA 2018.2.5'/
drwxr-xr-x 1 lenovo 197121 0 12月 4 13:59 IntelliJ%20IDEA%202018.2.5/
drwxr-xr-x 1 lenovo 197121 0 12月 20 19:39 linux/
drwxr-xr-x 1 lenovo 197121 0 5月 8 2019 Matlab/
-rw-r--r-- 1 lenovo 197121 186 10月 12 16:34 mby.txt
drwxr-xr-x 1 lenovo 197121 0 10月 23 13:58 Mobatek/
drwxr-xr-x 1 lenovo 197121 0 1月 3 2018 Multisim/
drwxr-xr-x 1 lenovo 197121 0 6月 30 11:46 MY_College/
drwxr-xr-x 1 lenovo 197121 0 12月 7 17:06 'MyEclipse Professional 2014'/
drwxr-xr-x 1 lenovo 197121 0 7月 13 15:32 'MySQL Datafiles'/
drwxr-xr-x 1 lenovo 197121 0 12月 2 08:15 navicat/
drwxr-xr-x 1 lenovo 197121 0 10月 30 15:31 'Navicat Premium 12'/
drwxr-xr-x 1 lenovo 197121 0 5月 5 2019 oraclexe/
drwxr-xr-x 1 lenovo 197121 0 12月 21 16:23 'Plants vs Zombies GOTY CHS'/
drwxr-xr-x 1 lenovo 197121 0 8月 23 23:18 'PowerDesigner 12'/
drwxr-xr-x 1 lenovo 197121 0 6月 24 14:41 QQ/
-rw-r--r-- 1 lenovo 197121 5 12月 2 01:43 README.txt
drwxr-xr-x 1 lenovo 197121 0 10月 16 17:21 RedisDesktopManager/
drwxr-xr-x 1 lenovo 197121 0 11月 15 10:02 scala/
drwxr-xr-x 1 lenovo 197121 0 10月 5 21:22 Small_software/
-rw-r--r-- 1 lenovo 197121 0 10月 3 13:36 Speed.log
-rw-r--r-- 1 lenovo 197121 3997 12月 12 19:27 storm.yaml
-rw-r--r-- 1 lenovo 197121 49 10月 10 15:57 suns.txt
drwxr-xr-x 1 lenovo 197121 0 12月 9 17:07 'System Volume Information'/
-rw-r--r-- 1 lenovo 197121 186 10月 25 12:57 testDownload01.txt
-rw-r--r-- 1 lenovo 197121 186 10月 25 12:59 testDownload02.txt
drwxr-xr-x 1 lenovo 197121 0 12月 22 17:36 testgit/
drwxr-xr-x 1 lenovo 197121 0 10月 30 21:32 tmp/
drwxr-xr-x 1 lenovo 197121 0 6月 23 20:00 TXEDU/
drwxr-xr-x 1 lenovo 197121 0 9月 12 2017 VC++6.0/
drwxr-xr-x 1 lenovo 197121 0 10月 21 19:09 'Virtual Machines'/
drwxr-xr-x 1 lenovo 197121 0 12月 1 23:02 VM/
drwxr-xr-x 1 lenovo 197121 0 10月 21 11:27 VMware/
drwxr-xr-x 1 lenovo 197121 0 10月 21 11:37 'VMware Workstation'/
-rw-r--r-- 1 lenovo 197121 225 10月 28 14:34 wcdata.txt
drwxr-xr-x 1 lenovo 197121 0 11月 19 10:58 WeChatDownload/
drwxr-xr-x 1 lenovo 197121 0 4月 15 2018 WPE_wps/
-rw-r--r-- 1 lenovo 197121 30 10月 10 16:04 xiaojr.txt
drwxr-xr-x 1 lenovo 197121 0 10月 28 13:35 图片/
drwxr-xr-x 1 lenovo 197121 0 12月 1 21:51 信号与系统历年真题/
drwxr-xr-x 1 lenovo 197121 0 12月 1 21:54 资料(全部拷贝)/
lenovo@LAPTOP-SNB6RGPG MINGW64 /d
$ cd 160test/
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/160test (master)
$ 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)
a.txt #红色
nothing added to commit but untracked files present (use "git add" to track)
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/160test (master)
$ git add a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/160test (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: a.txt #绿色
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/160test (master)
$ git commit -m "add a.txt"
[master 691ebdb] add a.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/160test (master)
$ 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
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/160test (master)
$ git push origin #推上去
fatal: HttpRequestException encountered.
▒▒▒▒▒▒▒▒ʱ▒▒▒▒
Username for 'https://github.com': githubmaby
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 263 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/githubmaby/160test.git
ff4788a..691ebdb master -> master
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/160test (master)
$ git pull origin #拉下来
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/githubmaby/160test
691ebdb..fd8da54 master -> origin/master
Updating 691ebdb..fd8da54
Fast-forward
a.txt | 1 +
1 file changed, 1 insertion(+)
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/160test (master)
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git remote -v #查看本地仓库有没有和远程仓库连接
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git remote add origin git@github.com:ytreytre/testgit.git #本地仓库和远程仓库进行连接
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git remote -v #查看本地仓库有没有和远程仓库连接
origin git@github.com:ytreytre/testgit.git (fetch)
origin git@github.com:ytreytre/testgit.git (push)
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git push -u origin master #将本地仓库的项目推送到远程仓库
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights #这个BUG怎么破
and the repository exists.
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git push -u origin master #把本地仓库推送到远程
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights #出现这种情况怎么办?
and the repository exists.
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git pull origin master #将本地仓库进行更新
#两者的区别:上面的是克隆的,这个是推的。
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git pull origin master
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have t
// 再试一次
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ git init
Reinitialized existing Git repository in D:/testgit/.git/
-
从GitHub上克隆一个仓库到本地。
-
生产一个SSH公钥,把公钥添加到GitHub的信任列表
-
在GitHub上创建一个git仓库。
-
通过ssh形式进行克隆
git clone github仓库远程地址
-
更新本地的仓库版本并提交到远程
- 修改文件
- git add
- git commit
- git push origin
-
将远程仓库的修改跟新到本地
git pull origin
-
-
从本地添加一个仓库与远程仓库关联
-
找到自己的项目目录,进入。 #进入src那层
-
git init 把项目目录交给git管理
-
在远程创建一个空仓库(不要交给git管理)
-
给本地仓库和刚创建远程仓库做一个连接
git remote add origin git@github.com:ytreytre/testgit.git
-
把本地仓库推送到远程
git push -u origin master
-
将修改更新到本地
git pull origin master
-
7.git的分支
-
分支概念
-
分支的切换和版本的切换
-
对分支的操作
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testgit (master)
$ cd ..
lenovo@LAPTOP-SNB6RGPG MINGW64 /d
$ cd testbranch/
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch
$ ls
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch
$ ll
total 0
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch
$ git init
Initialized empty Git repository in D:/testbranch/.git/
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (master)
$ git status
On branch master
Initial commit
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)
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (master)
$ git add a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (master)
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: a.txt #绿色
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (master)
$ git commit -m "new a.txt"
[master (root-commit) d901179] new a.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (master)
$ git status
On branch master
nothing to commit, working tree clean
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (master)
$ git checkout -b dev #创建并切换到dev分支
Switched to a new branch 'dev'
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (dev) #观察此处
$
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (dev)
$ git status
On branch dev
Untracked files:
(use "git add <file>..." to include in what will be committed)
b.txt #红色
nothing added to commit but untracked files present (use "git add" to track)
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (dev)
$ git add b.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (dev)
$ git status
On branch dev
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: b.txt #绿色
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (dev)
$ git commit -m "dev new b.txt"
[dev cbef3e4] dev new b.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (dev)
$ git status
On branch dev
nothing to commit, working tree clean
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (dev)
$ git checkout master #切换到master分支
Switched to branch 'master'
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (master) #观察此处
$
#观察本地仓库 ---- b.txt不见了
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (master)
$ git checkout dev #切换到dev分支
Switched to branch 'dev'
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (dev) #观察此处
$
#观察本地仓库 --- b.txt有出现了
#合并的话必须先切换到主分支
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (dev)
$ git checkout master
Switched to branch 'master'
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (master)
$ git merge dev #合并分支
Updating d901179..cbef3e4
Fast-forward
b.txt | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (master)
$ git branch #查看当前的所有的分支
dev
* master
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (master)
$ git branch -d dev #删除分支
Deleted branch dev (was cbef3e4).
lenovo@LAPTOP-SNB6RGPG MINGW64 /d/testbranch (master)
$ git branch #
* master
创建并切换到dev分支
git checkout -b dev ------------创建并切换到dev分支
1.创建分支
git branch dev -----------------创建dev分支
2.切换分支
git checkout dev --------------切换到dev分支
3.合并分支
git merge dev -----------------合并dev分支到master分支
4.删除分支
git branch -d dev --------------删除dev分支
5.查看当前所有分支
git branch ---------------------查看分支
8.git集成idea
-
配置github
-
初始化项目为git仓库
-
添加和提交
提交快捷键:ctrl + k
推送快捷键:ctrl+shift+k
-
打开git控制台、
alt+9
-
查看修改的内容或者撤销
-
将本地仓库分享到github
-
将github的修改更新到本地
快捷键:ctrl + t
-
将远程仓库下载到本地