(一)基本命令的使用(git動態演示)
注:參考Pro Git簡體中文版
注:參考Git官方文檔
注:參考Git中文文檔
注:參考Git官方文檔
注:參考易百Git教程
注:廖雪峯的官方網站
1.創建本地倉庫的操作步驟如下:
在D:\Gitlearn目錄下創建工作區並初始化本地倉庫
lenovo@Lenovo-PC MINGW64 /d/Gitlearn
$ mkdir respository //1.創建工作區目錄
lenovo@Lenovo-PC MINGW64 /d/Gitlearn
$ cd respository/ //2.進入工作區
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/respository
$ git init //3.執行完此命令後,初始化本地倉庫已經完成
Initialized empty Git repository in D:/Gitlearn/respository/.git/
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/respository (master)
$ ls -a //4.查看本地倉庫(.git目錄位於respository根目錄下)
./ ../ .git/
2.使用 git add +文件名把文件添加到Stage(暫存區),再使用git commit -m"描述信息"命令將文件提交到git倉庫
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ git add demo.txt //1.把文件添加到暫存區
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ git status //2.查看狀態
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: demo.txt
new file: test.txt
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ git commit -m"測試用例" //3.把暫存區的文件添加到git倉庫
[master 9327845] 測試用例
2 files changed, 2 insertions(+)
create mode 100644 demo.txt
create mode 100644 test.txt
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ git ls-files //4.查看暫存區是否有文件提交
demo.txt
readme.txt
test.txt
3.使用git rm+文件名刪除當前工作空間中和索引中的文件
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ ls //1.工作區中的文件
demo.txt readme.txt test.txt
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ git rm readme.txt //2.刪除git倉庫中的文件(刪除多個文件空格隔開)
rm 'readme.txt'
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ git status //3.查看刪除狀態
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: readme.txt //刪除文件的名稱
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ git ls-files //4.查看刪除後git倉庫中的文件
demo.txt
test.txt
4.使用git log命令查看歷史日誌
-
git log 查看提交歷史記錄
-
git log - -oneline 或者 git log - -pretty=oneline 以精簡模式顯示
-
git log - -graph 以圖形模式顯示
-
git log - -stat 顯示文件更改列表
-
git log - -author= ‘name’ 顯示某個作者的日誌
-
git log -p filepath 查看某個文件的詳細修改
-
git log -L start,end:filepath 查看某個文件某幾行範圍內的修改記錄
-
git log - -stat commitId 或者 git show - -stat commitId 查看某一次提交的文件修改列表
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ git log // 1.使用此命令查看日誌
commit 9327845036d7f9e0203abbb299b330aee208c49f (HEAD -> master)
Author: Kaina <[email protected]>
Date: Sat Jul 14 22:08:21 2018 +0800
測試用例
commit 97c34a16cf22d3725f5c1e07af1df3877d7e29da
Author: Kaina <[email protected]>
Date: Sat Jul 14 21:48:17 2018 +0800
測試添加文件到倉庫中
5.使用git push把本地倉庫中的代碼提交到遠程版本倉庫中
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ git config --global user.name"Kaina" //1,賬號
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ git config --global user.email "郵箱" //2.郵箱
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ git remote add origin https://github.com/666666666/Test.git //3.添加到遠程倉庫
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/repository (master)
$ git push -u origin master //4.推送到主分支
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 554 bytes | 277.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To https://github.com/666666666/Test.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
2.git 提示fatal: remote origin already exists 解決辦法
1.先刪除遠程 Git 倉
$ git remote rm origin
2.再添加遠程 Git 倉庫
$ git remote add origin 倉庫地址
3.如果執行 git remote rm origin 依然報錯,可以手動修改gitconfig文件的內容
$ vi .git/config //把config文件的 [remote “origin”] 一行刪掉
lenovo@Lenovo-PC MINGW64 ~/Desktop/項目/ssm-crud (master)
$ git remote add origin https://github.com/666666666/Demo1.git
fatal: remote origin already exists. //1.顯示文件存在
lenovo@Lenovo-PC MINGW64 ~/Desktop/項目/ssm-crud (master)
$ git remote rm origin //2.刪除此文件
lenovo@Lenovo-PC MINGW64 ~/Desktop/項目/ssm-crud (master)
//3.將已有的文件添加到倉庫
$ git remote add origin https://github.com/666666666/Demo1.git
lenovo@Lenovo-PC MINGW64 ~/Desktop/項目/ssm-crud (master)
$ git push -u origin master //4.將項目文件推到master分支
Enumerating objects: 81, done.
Counting objects: 100% (81/81), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (69/69), done.
Writing objects: 100% (81/81), 342.71 KiB | 2.21 MiB/s, done.
Total 81 (delta 10), reused 0 (delta 0)
remote: Resolving deltas: 100% (10/10), done.
To https://github.com/666666666/Demo1.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
6.git clone +url克隆遠程版本庫
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/TestCloneRepository (master)
#1.把遠程倉庫克隆到本地倉庫的libgit2
$ git clone https://github.com/libgit2/libgit2
Cloning into 'libgit2'...
remote: Counting objects: 82264, done.
remote: Compressing objects: 100% (23369/23369), done.
remote: Total 82264 (delta 57440), reused 82254 (delta 57430), pack-reused 0
Receiving objects: 100% (82264/82264), 37.70 MiB | 1.04 MiB/s, done.
Resolving deltas: 100% (57440/57440), done.
Checking out files: 100% (5653/5653), done.
7.git branch命令使用詳解
操作 | 命令 |
---|---|
1.查看當前有哪些分支 | $ git branch |
2.新建一個分支 | $ git branch dev2 |
3.切換到指定分支 | $ git checkout dev2 |
4. 查看本地和遠程分支 | $ git branch -a |
5.將更改添加到新建分支上 | $ git push origin dev2 |
6.修改分支的名字 | $ git branch -m dev2 version.2 |
7.刪除遠程分支 | $ git push origin --delete dev2 |
8.合併分支 | $ git merge version.2 |
8.git checkout命令的作用:在不同的分支之間進行切換
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/TestCloneRepository (master) #默認分支
$ git branch #1.查看git倉庫的分支
dev1
dev2
* master
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/TestCloneRepository (master)
$ git checkout dev1 #2.切換到dev1分支
Switched to branch 'dev1'
lenovo@Lenovo-PC MINGW64 /d/Gitlearn/TestCloneRepository (dev1) #切換到dev1分支
$
9.git stash命令:將當前未提交的工作存入Git工作棧中,時機成熟的時候在應用回來
注:參考git stash命令詳解
注:易百教程git stash命令
10.git pull命令:把遠程倉庫pull到本地倉庫
11.配置SSH,生成公鑰和私鑰
lenovo@Lenovo-PC MINGW64 ~
$ git config --global user.name kaina //1.配置賬號
lenovo@Lenovo-PC MINGW64 ~
$ git config --global user.email "自己的郵箱" //2.配置郵箱
lenovo@Lenovo-PC MINGW64 ~
$ ssh-keygen -t rsa -C "自己的郵箱" //3.生成SSH
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/lenovo/.ssh/id_rsa):
/c/Users/lenovo/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/lenovo/.ssh/id_rsa. //4.生成公鑰文件
Your public key has been saved in /c/Users/lenovo/.ssh/id_rsa.pub. //5.生成私鑰文件
The key fingerprint is:
SHA256:1CffJc6gg+ELZvNMU8SJRNS7FOvqRo50CujdaVqd9/E [email protected]
The key's randomart image is: //6.表示SSH公鑰私鑰生成成功
+---[RSA 2048]----+
| +++.. |
| .o= |
| o ++o . .|
| o ++= = o |
| . = Soo.. + |
| . .o.Bo+o. |
| . . +.B*.. . |
| . ..* +. . o |
| .o o. . E |
+----[SHA256]-----+
12.將本地磁盤保存的項目上傳到Github
lenovo@Lenovo-PC MINGW64 ~/Desktop/項目/SSM項目/AJax實現分頁功能/LearnProgram (master)
$ git init // 1.初始化倉庫
Reinitialized existing Git repository in C:/Users/lenovo/Desktop/項目/SSM項目/AJax實現分頁功能/LearnProgram/.git/
lenovo@Lenovo-PC MINGW64 ~/Desktop/項目/SSM項目/AJax實現分頁功能/LearnProgram (master)
$ git add . //2.把所有項目文件添加到倉庫
warning: LF will be replaced by CRLF in src/main/resources/spring-bean.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/resources/springmvc.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/webapp/static/bootstrap-3.3.7-dist/css/bootstrap-theme.css.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/webapp/static/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/webapp/static/bootstrap-3.3.7-dist/css/bootstrap.css.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/webapp/static/bootstrap-3.3.7-dist/css/bootstrap.min.css.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/webapp/static/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.svg.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/webapp/static/bootstrap-3.3.7-dist/js/bootstrap.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/webapp/static/bootstrap-3.3.7-dist/js/bootstrap.min.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in src/main/webapp/static/bootstrap-3.3.7-dist/js/npm.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in target/classes/spring-bean.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in target/classes/springmvc.xml.
The file will have its original line endings in your working directory.
lenovo@Lenovo-PC MINGW64 ~/Desktop/項目/SSM項目/AJax實現分頁功能/LearnProgram (master)
$ git commit -m "提交SSM項目" //3.提交項目
[master (root-commit) 5d8cf7c] 提交SSM項目
79 files changed, 13281 insertions(+)
create mode 100644 .classpath
create mode 100644 .project
create mode 100644 .settings/.jsdtscope
create mode 100644 .settings/org.eclipse.jdt.core.prefs
create mode 100644 .settings/org.eclipse.m2e.core.prefs
create mode 100644 .settings/org.eclipse.wst.common.component
create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml
create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.container
create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.name
create mode 100644 .settings/org.eclipse.wst.validation.prefs
create mode 100644 mbg.xml
create mode 100644 pom.xml
create mode 100644 src/main/java/com/wang/ssm/bean/Department.java
create mode 100644 src/main/java/com/wang/ssm/bean/DepartmentExample.java
create mode 100644 src/main/java/com/wang/ssm/bean/Employee.java
create mode 100644 src/main/java/com/wang/ssm/bean/EmployeeExample.java
create mode 100644 src/main/java/com/wang/ssm/bean/Msg.java
create mode 100644 src/main/java/com/wang/ssm/controller/EmployeeControlller.java
create mode 100644 src/main/java/com/wang/ssm/dao/DepartmentMapper.java
create mode 100644 src/main/java/com/wang/ssm/dao/EmployeeMapper.java
create mode 100644 src/main/java/com/wang/ssm/servicce/EmployeeService.java
create mode 100644 src/main/java/com/wang/ssm/test/MBGTest.java
create mode 100644 src/main/java/com/wang/ssm/test/MapperTest.java
create mode 100644 src/main/java/com/wang/ssm/test/SpringMVCTest.java
create mode 100644 src/main/resources/dbconfig.properties
create mode 100644 src/main/resources/mapper/DepartmentMapper.xml
create mode 100644 src/main/resources/mapper/EmployeeMapper.xml
create mode 100644 src/main/resources/mybatis-config.xml
create mode 100644 src/main/resources/spring-bean.xml
create mode 100644 src/main/resources/springmvc.xml
create mode 100644 src/main/webapp/META-INF/MANIFEST.MF
create mode 100644 src/main/webapp/WEB-INF/web.xml
create mode 100644 src/main/webapp/index.jsp
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/css/bootstrap-theme.css
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/css/bootstrap-theme.css.map
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css.map
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/css/bootstrap.css
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/css/bootstrap.css.map
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/css/bootstrap.min.css
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/css/bootstrap.min.css.map
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.eot
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.svg
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.ttf
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.woff
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.woff2
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/js/bootstrap.js
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/js/bootstrap.min.js
create mode 100644 src/main/webapp/static/bootstrap-3.3.7-dist/js/npm.js
create mode 100644 src/main/webapp/static/js/jquery-1.12.4.min.js
create mode 100644 target/classes/com/wang/ssm/bean/Department.class
create mode 100644 target/classes/com/wang/ssm/bean/DepartmentExample$Criteria.class
create mode 100644 target/classes/com/wang/ssm/bean/DepartmentExample$Criterion.class
create mode 100644 target/classes/com/wang/ssm/bean/DepartmentExample$GeneratedCriteria.class
create mode 100644 target/classes/com/wang/ssm/bean/DepartmentExample.class
create mode 100644 target/classes/com/wang/ssm/bean/Employee.class
create mode 100644 target/classes/com/wang/ssm/bean/EmployeeExample$Criteria.class
create mode 100644 target/classes/com/wang/ssm/bean/EmployeeExample$Criterion.class
create mode 100644 target/classes/com/wang/ssm/bean/EmployeeExample$GeneratedCriteria.class
create mode 100644 target/classes/com/wang/ssm/bean/EmployeeExample.class
create mode 100644 target/classes/com/wang/ssm/bean/Msg.class
create mode 100644 target/classes/com/wang/ssm/controller/EmployeeControlller.class
create mode 100644 target/classes/com/wang/ssm/dao/DepartmentMapper.class
create mode 100644 target/classes/com/wang/ssm/dao/EmployeeMapper.class
create mode 100644 target/classes/com/wang/ssm/servicce/EmployeeService.class
create mode 100644 target/classes/com/wang/ssm/test/MBGTest.class
create mode 100644 target/classes/com/wang/ssm/test/MapperTest.class
create mode 100644 target/classes/com/wang/ssm/test/SpringMVCTest.class
create mode 100644 target/classes/dbconfig.properties
create mode 100644 target/classes/mapper/DepartmentMapper.xml
create mode 100644 target/classes/mapper/EmployeeMapper.xml
create mode 100644 target/classes/mybatis-config.xml
create mode 100644 target/classes/spring-bean.xml
create mode 100644 target/classes/springmvc.xml
create mode 100644 target/m2e-wtp/web-resources/META-INF/MANIFEST.MF
create mode 100644 target/m2e-wtp/web-resources/META-INF/maven/com.gaolei.ssm/ssm-crud/pom.properties
create mode 100644 target/m2e-wtp/web-resources/META-INF/maven/com.gaolei.ssm/ssm-crud/pom.xml
create mode 100644 target/m2e-wtp/web-resources/META-INF/maven/com.wang.ssm/ssm-crud/pom.properties
create mode 100644 target/m2e-wtp/web-resources/META-INF/maven/com.wang.ssm/ssm-crud/pom.xml
lenovo@Lenovo-PC MINGW64 ~/Desktop/項目/SSM項目/AJax實現分頁功能/LearnProgram (master)
$ git remote add origin https://github.com/666666666/JavaProject.git
fatal: remote origin already exists. //4.將項目添加到github倉庫,報此錯誤
lenovo@Lenovo-PC MINGW64 ~/Desktop/項目/SSM項目/AJax實現分頁功能/LearnProgram (master)
$ git remote rm origin //5.報以上錯誤使用此命令
lenovo@Lenovo-PC MINGW64 ~/Desktop/項目/SSM項目/AJax實現分頁功能/LearnProgram (master)
$ git remote add origin https://github.com/666666666/JavaProject.git //6.push到遠程倉庫
lenovo@Lenovo-PC MINGW64 ~/Desktop/項目/SSM項目/AJax實現分頁功能/LearnProgram (master)
$ git push -u origin master //7.將項目源碼添加到master分支
Enumerating objects: 115, done.
Counting objects: 100% (115/115), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (96/96), done.
Writing objects: 100% (115/115), 357.86 KiB | 1.54 MiB/s, done.
Total 115 (delta 17), reused 0 (delta 0)
remote: Resolving deltas: 100% (17/17), done.
To https://github.com/666666666/JavaProject.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.