liqiang@username MINGW64 ~/Desktop
$ mkdir TestGit        新建目录

liqiang@username MINGW64 ~/Desktop
$ cd testGit    进入目录

liqiang@username MINGW64 ~/Desktop/testGit
$ git clone https://github.com/qiao-zhi/Git.git  克隆远程仓库(克隆的时候连远程的仓库名字克隆下来。也就是会克隆一个文件夹,名字为远程仓库名字)
Cloning into 'Git'...
warning: You appear to have cloned an empty repository.

liqiang@username MINGW64 ~/Desktop/testGit
$ LS                查看目录
Git

liqiang@username MINGW64 ~/Desktop/testGit
$ git init              初始化目录为git仓库
Initialized empty Git repository in C:/Users/liqiang/Desktop/TestGit/.git/

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ ls
Git/

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ touch ww.txt  qq.txt      创建两个文件

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ ls
Git/  qq.txt  ww.txt

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ git add .          加入索引(暂存区)

git rm -r --cached .      删除本地的索引重新添加索引

git add .                                      添加索引

git ls-files                   查看已经添加索引的文件

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ vim ww.txt        编辑ww.txt

$ git status -s    查看在你上次提交之后是否有修改。不带-s参数以获得详尽的结果输出
M WebContent/js/public/menu.js
M src/cn/xm/exam/mapper/question/custom/QuestionsCustomMapper.xml

$ git status    查看在你上次提交之后是否有修改。带-s参数以获得简短的结果输出
On branch qlq
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: WebContent/js/public/menu.js
modified: src/cn/xm/exam/mapper/question/custom/QuestionsCustomMapper.xml

no changes added to commit (use "git add" and/or "git commit -a")

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ git diff          查看具体的变化,查看执行 git status 的结果的详细信息。
diff --git a/ww.txt b/ww.txt
index e69de29..262ae9a 100644
--- a/ww.txt
+++ b/ww.txt
@@ -0,0 +1 @@
+insert row

尚未缓存的改动:git diff
查看已缓存的改动: git diff --cached
查看已缓存的与未缓存的所有改动:git diff HEAD
显示摘要而非整个 diff:git diff --stat

查看本地两个分支的不同:

git diff master qlq    查看本地master分支和qlq分支的不同

git diff [branchA] [branchB] >>d:/diff/exportname.diff    将比较结果重定向到文件中

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ git commit -m "这是测试"    提交到本地仓库
[master (username-commit) 62d2e68] 这是测试
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 qq.txt
 create mode 100644 ww.txt

git log 查看commit的历史  
git show <commit-hash-id>查看某次commit的修改内容
git log -p <filename>查看某个文件的修改历史
git log -p -2查看最近2次的更新内容

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ git remote add origin https://github.com/qiao-zhi/Git.git  连接远程仓库

$ git remote -v  #查看远程地址信息
origin git@github.com:qiao-zhi/jwxt.git (fetch)
origin git@github.com:qiao-zhi/jwxt.git (push)

$ git remote rm origin      断开与远程的连接

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ git branch
* master

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ git push -u origin master        push到远程仓库的master分值
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 225 bytes | 225.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/qiao-zhi/Git.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

git push -f -u origin master  如果需要强行推送到服务器

liqiang@username MINGW64 /e/xiangmu/Exam (qiaoliqiang)
$ git push origin qiaoliqiang    push到远程的qiaoliqiang分支
Counting objects: 24, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (17/17), done.
Writing objects: 100% (24/24), 2.00 KiB | 341.00 KiB/s, done.
Total 24 (delta 11), reused 0 (delta 0)
remote: Resolving deltas: 100% (11/11), completed with 9 local objects.
To https://github.com/qiao-zhi/Exam.git
 * [new branch]      qiaoliqiang -> qiaoliqiang

$ git push origin dev:qlq  #本地的dev分支提交到远程的qlq分支
Counting objects: 98, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (78/78), done.
Writing objects: 100% (98/98), 25.13 KiB | 0 bytes/s, done.
Total 98 (delta 54), reused 0 (delta 0)
remote: Resolving deltas: 100% (54/54), completed with 32 local objects.
To github.com:qiao-zhi/jwxt.git
f91df1c..619ba18 dev -> qlq

$ git ls-files     查看远程已经提交的文件

$ git ls-files | less   分页显示

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ git branch ww      创建分支

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ git branch      查看分支
* master
  ww

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ git checkout ww    切换到ww分支
Switched to branch 'ww'
M       ww.txt

liqiang@root MINGW64 /e/xiangmu/Exam2/Exam (master)
$ git checkout -b qiaoliqiang      创建并立即切换到qiaoliqiang分支
Switched to a new branch 'qiaoliqiang'

liqiang@root MINGW64 /e/xiangmu/Exam2/Exam (qiaoliqiang)

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ git branch -d del    删除分值
Deleted branch del (was 62d2e68).

liqiang@username MINGW64 ~/Desktop/testGit (master)
$ git branch    查看分值
* master

liqiang@username MINGW64 /e/xiangmu/Exam (master)
$ git branch -r    查看远程分支
  origin/qiaoliqiang

liqiang@username MINGW64 /e/xiangmu/Exam (master)
$ git branch    查看本地分支
* master
  qiaoliqiang

liqiang@username MINGW64 /e/xiangmu/Exam (master)
$ git branch -a    查看所有分支
* master
  qiaoliqiang
  remotes/origin/qiaoliqiang  (远程分支)

$ git push origin --delete qlq  删除远程的qlq分支(有时候我用于处理发起合并请求但又不想合并代码)
To github.com:qiao-zhi/jwxt.git
- [deleted] qlq

查看当前详细分支信息(可看到当前分支与对应的远程追踪分支):

git branch -vv

查看当前远程仓库信息

git remote -vv

liqiang@usernameMINGW64 /e/xiangmu/Exam2/Exam (master)
$ git pull    拉取远程的master分支并且自动合并到当前分支
remote: Counting objects: 48, done.
remote: Compressing objects: 100% (42/42), done.
remote: Total 48 (delta 36), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (48/48), done.

liqiang@usernameMINGW64 /e/xiangmu/Exam2/Exam (qiaoliqiang)
$ git merge master    将本地的master合并到当前的qiaoliqiang分支
Updating 9c82009..1285019
Fast-forward
WebContent/js/outDepart/outEmployeeAllot.js | 1 +
WebContent/view/outDepart/outEmployeeAllot.jsp | 1 +
.../employee/out/ExportExcelEmployeeOutInfoAction.java | 16 ++++++++++++++++
.../employee/out/custom/EmployeeOutCustomMapper.java | 3 +++
.../employee/out/custom/EmployeeOutCustomMapper.xml | 18 +++++++++++++++++-
.../impl/employee/out/EmployeeOutServiceImpl.java | 4 +++-
6 files changed, 41 insertions(+), 2 deletions(-)

$ git merge origin/master  将远程的master分支合并到当前分支,用于git fetch之后合并对应的分支

liqiang@usernameMINGW64 /e/xiangmu/Exam2/Exam (qiaoliqiang)
$ git pull origin master      将远程的master分支拉倒本地的qiaoliqiang分支

liqiang@usernameMINGW64 /e/xiangmu/Exam2/Exam (master)
$ git merge qiaoliqiang    将本地的qiaoliqiang分支合并到本地的master分支
Updating 378a8ed..29af29b
Fast-forward
WebContent/css/home/header.css | 26 +++++-
WebContent/js/examParper/exam/addExam.js | 39 ++++++++-
WebContent/js/examParper/exam/updateExam.js | 28 ++++++-
WebContent/js/gradeManage/gradeEmpInfo.js | 2 +-
WebContent/js/lineExam/ExamParper.js | 2 +-
WebContent/js/lineExam/examInterface.js | 2 +-
WebContent/js/outDepart/outdepartMnanage.js | 2 +-
WebContent/js/overhaul/overhaulInfo.js | 5 +-
.../modifyQuestion/modifyquestion.js | 2 +-
WebContent/view/examParper/exam/addExam.jsp | 77 ++++++++++--------
WebContent/view/examParper/exam/modifyExam.jsp | 93 ++++++++++++----------
WebContent/view/lineExam/ExamParper.jsp | 6 +-
WebContent/view/outDepart/outdepartManage.jsp | 1 +
WebContent/view/overhaul/overhaulInfo.jsp | 1 +
WebContent/view/public/header.jsp | 7 +-
.../view/questionLibrary/modifyQuestionPage.jsp | 4 +-
.../exam/action/employee/out/UpdateUnitAction.java | 2 +-
src/cn/xm/exam/action/exam/exam/AddExamAction.java | 11 ++-
.../xm/exam/action/exam/exam/UpdateExamAction.java | 11 ++-
.../out/custom/EmpoutDistributeCustomMapper.xml | 8 +-
.../employee/out/custom/UnitCustomMapper.xml | 15 ++--
src/cn/xm/exam/service/exam/exam/ExamService.java | 4 +-
.../service/impl/exam/exam/ExamServiceImpl.java | 10 +--
.../impl/grade/EmployeeExamServiceImpl.java | 83 ++++++++++---------
24 files changed, 293 insertions(+), 148 deletions(-)

liqiang@usernameMINGW64 /e/xiangmu/Exam2/Exam (master)
$ git branch -d qiaoliqiang                                删除本地的qiaoliqiang分支(有时候删不掉)
warning: not deleting branch 'qiaoliqiang' that is not yet merged to
'refs/remotes/origin/qiaoliqiang', even though it is merged to HEAD.
error: The branch 'qiaoliqiang' is not fully merged.
If you are sure you want to delete it, run 'git branch -D qiaoliqiang'.

liqiang@usernameMINGW64 /e/xiangmu/Exam2/Exam (master)
$ git branch -D qiaoliqiang      强行删除本地的qiaoliqiang分支(有时候删不掉)
Deleted branch qiaoliqiang (was 1285019).

liqiang@usernameMINGW64 /e/xiangmu/Exam2/Exam (master)
$ git branch qiaoliqiang  创建qiaoliqiang分支

liqiang@usernameMINGW64 /e/xiangmu/Exam2/Exam (master)
$ git checkout qiaoliqiang  切换到qiaoliqiang分支
Switched to branch 'qiaoliqiang'

liqiang@userMINGW64 ~/Desktop/test (master)
$ git diff
diff --git a/1.txt b/1.txt
index de50c2b..8dbfb6e 100644
--- a/1.txt
+++ b/1.txt
@@ -1,3 +1,4 @@
11111111111111111111111111111
22222222222222222222222222222
33333333333333333333333333333
+44444444444444444444444444444

liqiang@userMINGW64 ~/Desktop/test (master)
$ git checkout -- 1.txt  撤销从上次提交之后对某个文件的修改

$ git checkout -- *  撤销从上次提交之后对所有文件的修改

$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)

aqjc/src/com/tyust/Test.xml

nothing added to commit but untracked files present (use "git add" to track)

liqiang@root MINGW64 /e/xiangmu/sbgl (master)
$ git clean -df      删除一些没有git add的文件
Removing aqjc/src/com/tyust/Test.xml

liqiang@root MINGW64 /e/xiangmu/sbgl (master)
$ git status
On branch master
nothing to commit, working tree clean

liqiang@root MINGW64 /e/xiangmu/sbgl (master)
$ git checkout . && git clean -xdf  彻底的恢复到上次提交之后,删除所有的修改并删除增加的文件
Removing aqjc/build/classes/com/

liqiang@root MINGW64 /e/xiangmu/sbgl (master)
$ git status
On branch master
nothing to commit, working tree clean

查看帮助信息相关操作:(-help是在git窗口查看,--help是打开浏览器查看信息比较全)

liqiang@root MINGW64 /e/IDEAWorkSpace/jwxt (qlq)
$ git help remote       打开浏览器查看 git remote的帮助信息(等价于    git rm --help  )

$ git branch -help    在git窗口查看命令的帮助信息
usage: git branch [<options>] [-r | -a] [--merged | --no-merged]
or: git branch [<options>] [-l] [-f] <branch-name> [<start-point>]
or: git branch [<options>] [-r] (-d | -D) <branch-name>...
or: git branch [<options>] (-m | -M) [<old-branch>] <new-branch>
or: git branch [<options>] [-r | -a] [--points-at]
or: git branch [<options>] [-r | -a] [--format]

liqiang@userMINGW64 ~/Desktop/test (master)
$ git diff

/********************************S 回退版本相关操作****************************************************/

liqiang@root MINGW64 ~/Desktop/test (master)
$ git log  所有的历史版本,获取某个历史版本的id(每次提交的日期与生存的一个ID与提交的名称,根据提交的名称与日期确定回退的版本ID)
commit 39f0dd215a5f98466e3b4a4f5668911c3f5ed99f (HEAD -> master)
Author: qiaozhi <qiao_liqiang@163.com>
Date: Mon Jan 29 18:59:18 2018 +0800

3

commit b7a836826cb97cbe678bd45f4fabef8d87365806
Author: qiaozhi <qiao_liqiang@163.com>
Date: Mon Jan 29 18:58:27 2018 +0800

2

commit 662422ffe73df4131b16fe99dd180bb338492fb4
Author: qiaozhi <qiao_liqiang@163.com>
Date: Mon Jan 29 18:51:12 2018 +0800

11111

liqiang@root MINGW64 ~/Desktop/test (master)
$ git reset --hard 662422ffe73df4131b16fe99dd180bb338492fb4  回退到第一次提交之后(11111提交之后)
HEAD is now at 662422f 11111

liqiang@root MINGW64 ~/Desktop/test (master)
$ git status
On branch master
nothing to commit, working tree clean

liqiang@root MINGW64 ~/Desktop/test (master)
$ cat 1.txt                  
11111111111111111111111111111


git push -f -u origin master
如果需要强行推送到服务器

/********************************E 回退版本相关操作****************************************************/

/*******S  git stash保存和恢复进度相关操作*************/

git stash

  保存当前工作进度,会把暂存区和工作区的改动保存起来。执行完这个命令后,在运行git status命令,就会发现当前是一个干净的工作区,没有任何改动。使用git stash save 'message...'可以添加一些注释

git stash list

  显示保存进度的列表。也就意味着,git stash命令可以多次执行。

git stash pop [–index] [stash_id]

  git stash pop 恢复最新的进度到工作区。git默认会把工作区和暂存区的改动都恢复到工作区。

  git stash pop --index 恢复最新的进度到工作区和暂存区。(尝试将原来暂存区的改动还恢复到暂存区)

  git stash pop stash@{1}恢复指定的进度到工作区。stash_id是通过git stash list命令得到的 
通过git stash pop命令恢复进度后,会删除当前进度。

git stash apply [–index] [stash_id]

  除了不删除恢复的进度之外,其余和git stash pop 命令一样。

git stash drop [stash_id]

  删除一个存储的进度。如果不指定stash_id,则默认删除最新的存储进度。

  

  $ git stash list
    stash@{0}: WIP on dev: 908e069 <D0>޸<C4><C1>˵<E3><D7>ֵ䶫<CE><F7>
    stash@{1}: WIP on master: 02f0945 ȡ<CF><FB>xml<CA><C2><CE>

【自己的练习git】自己的git练习的更多相关文章

  1. git init和git init -bare区别

    1 Git init  和 git init –bare 的区别 用"git init"初始化的版本库用户也可以在该目录下执行所有git方面的操作.但别的用户在将更新push上来的 ...

  2. 小丁带你走进git世界一-git简单配置

    小丁带你走进git世界一-git简单配置 1.github的简单配置 配置提交代码的信息,例如是谁提交的代码之类的. git config  –global user.name BattleHeaer ...

  3. Git(远程仓库:git@oschina)-V2.0

    1.注册git@osc(也就是“码云”) 这里会提示注册密码==push密码,反正一定要记住的东西.   2.安装git 这里要设置个人信息 git config --list //查看git信息 g ...

  4. git pull和git fetch的区别

    Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge Git fetch origin master git log ...

  5. [.net 面向对象程序设计进阶] (26) 团队开发利器(五)分布式版本控制系统Git——图形化Git客户端工具TortoiseGit

    [.net 面向对象程序设计进阶] (26) 团队开发利器(五)分布式版本控制系统Git——图形化Git客户端工具TortoiseGit 读前必备: 接上篇: 分布式版本控制系统Git——使用GitS ...

  6. Git:Git初体验——Git安装配置

    作为即将成为一个程序员的男人,一直在听别人说Git多好多好,之前也随便了解了一些,但是始终没有决心去学会.现在大四了,只有毕设和一门开学六七周只去过一次课的全员必修课外,也没有什么事情做,何不去做这些 ...

  7. git rebase与 git合并(error: failed to push some refs to)解决方法

    1.遇到的问题 本地有一个git仓库,在github上新建了一个空的仓库,但是更新了REWADME.md的信息,即在github上多了一个提交. 关联远程仓库,操作顺序如下: git remote a ...

  8. Git fetch和git pull的区别

    Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge git fetch origin mastergit log - ...

  9. 代码回滚:git reset、git checkout和git revert区别和联系

    git reset.git checkout和git revert是你的Git工具箱中最有用的一些命令.它们都用来撤销代码仓库中的某些更改,而前两个命令不仅可以作用于提交,还可以作用于特定文件. 因为 ...

  10. git branch(git 的branch 使用方法)

    查看分支:         $ git branch    该命令会类出当先项目中的所有分支信息,其中以*开头的表示当前所在的分支.参数-r列出远程仓库中的分支,而-a则远程与本地仓库的全部分支. 创 ...

随机推荐

  1. nginx修改nginx.conf配置可以https访问

    修改nginx.conf,参照如下更改配置server { listen 443; server_name abc.com; // 访问域名 ssl on; root /var/www/bjubi.c ...

  2. L2TP用户添加和删除、搜索脚本

    #!/bin/bash #author Template . /etc/init.d/functions DATE_TIME=$(date +%F-%T) FILE_PATH='/etc/ppp/ch ...

  3. 50 道 CSS 基础面试题及答案

    1 介绍一下标准的CSS的盒子模型?与低版本IE的盒子模型有什么不同的? 标准盒子模型:宽度=内容的宽度(content)+ border + padding + margin 低版本IE盒子模型:宽 ...

  4. python爬取豆瓣top250的电影数据并存入excle

    爬取网址: https://movie.douban.com/top250 一:爬取思路(新手可以看一下) : 1:定义两个函数,一个get_page函数爬取数据,一个save函数保存数据,mian中 ...

  5. 解析XML格式数据

    学习解析XML格式的数据前,搭建一个简单的web服务器,在这个服务器上提供xml文本用于练习. 一.搭建Apache服务器 在Apache官网下载编译好的服务器程序,安装.对于Windows来说127 ...

  6. 将SpringBoot默认Json解析框架jackson替换成fastjson

    步骤一:引入依赖<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson< ...

  7. wget常用下载命令

    wget wget是一个从网络上自动下载文件的自由工具,支持通过HTTP.HTTPS.FTP三个最常见的TCP/IP协议下载,并可以使用HTTP代理.wget名称的由来是“World Wide Web ...

  8. 第5模块闯关CSS练习题

    1.列举你知道的css选择器? 说道css选择器,大家都知道有许多种,但是真要你去掰着手指头数一数的话,你可能需要数几分钟.其实这么多选择器,完全可以分为两类: 标签选择器(*是特殊情况),可但标签, ...

  9. C++文件读写之对象的读写

    这里以一个简单的学生信息管理系统为例. 首先是对象的建立,包括姓名,学号,成绩,学分,等 如下: 这里面包括两个子对象, class Student { public: Student() :scor ...

  10. ADO之密码验证--3次错误就锁定『改进』

    这里使用了SqlHelper,简化程序 自己写一个SqlHelper,把数据库的连接等都写到里面去. 首先把连接字符串添加到配置文件里去,右键解决方案-->添加新建项-->选择应用程序配置 ...