【自己的练习git】自己的git练习
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.
补充:直接clone某个分支
git clone -b v1.3 git地址
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
补充:git查看本地和远程分支对应关系
$ git branch -vv * dev 0b58eac [origin/dev] 修改前端打包目录 master d9a40af [origin/master] 代码调试
# 设置分支对应关系
git branch --set-upstream-to=origin/develop
或者
git branch -u origin/develop
补充:切换到某个分支并且拉取代码
git checkout -b develop origin/develop # 实则会切出分支到develop并到远程的develop分支拉取代码
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><C4>Ϊע<BD><E2><CA><C2><CE><F1>
$ git stash drop stash@{0} 删除对应的存储的进度
Dropped stash@{0} (06bc6336539b210226839cf34e1d367348d8602f)
$ git stash list
stash@{0}: WIP on master: 02f0945 ȡ<CF><FB>xml<CA><C2><CE><C4>Ϊע<BD><E2><CA><C2><CE><F1>
git stash clear
删除所有存储的进度。
/******E git stash保存和恢复进度相关操作**********/
/****S 打tag和删除tag以及打release相关命令*/
删除tag相关:
git tag -d [tag];
git push origin :[tag]
例如:
Administrator@MicroWin10-1535 MINGW64 /e/xiangmu/tourism (master) $ git tag #查看tag v0.1 Administrator@MicroWin10-1535 MINGW64 /e/xiangmu/tourism (master) $ git tag -d v0.1 #删除本地tag Deleted tag 'v0.1' (was ee2b078) Administrator@MicroWin10-1535 MINGW64 /e/xiangmu/tourism (master) $ git push origin :v0.1 #删除远程tag To https://github.com/qiao-zhi/tourism.git - [deleted] v0.1
Administrator@MicroWin10-1535 MINGW64 /e/xiangmu/tourism (master) $ git log commit e46a3da827fc7f0494d1fa0c62e35a2d0a980d09 (HEAD -> master, origin/master, origin/HEAD) Author: qiao_zhi <qiao_liqiang@163.com> Date: Wed Mar 27 18:09:13 2019 +0800 增加注册用户功能 commit 6bd3bab5c8a56c457c6aee8ea6365d92891a8f5e Author: qiaozhi <qiao_liqiang@163.com> Date: Tue Mar 26 21:47:58 2019 +0800 完善目录 commit 2f2aafa1169a2489ff6cf505df312fca813a3f86 Author: qiaozhi <qiao_liqiang@163.com> Date: Tue Mar 26 21:35:03 2019 +0800 init Administrator@MicroWin10-1535 MINGW64 /e/xiangmu/tourism (master) #在某次提交记录上打tag $ git tag v1.0.0 e46a3da827fc7f0494d1fa0c62e35a2d0a980d09 Administrator@MicroWin10-1535 MINGW64 /e/xiangmu/tourism (master) $ git tag #查看tag v1.0.0 Administrator@MicroWin10-1535 MINGW64 /e/xiangmu/tourism (master) $ git push origin v1.0.0 #本地tag推到远程 Total 0 (delta 0), reused 0 (delta 0) To https://github.com/qiao-zhi/tourism.git * [new tag] v1.0.0 -> v1.0.0
总结:
git tag -a V1 -m 'release 1' #创建了本地一个版本 V1 ,并且添加了附注信息 'release 1' git tag #查看tag git show V1 #查看tag 详情 git push origin --tags #推送tag git tag -d V1 #删除本地tag git push origin :refs/tags/V1 #删除远程V1 tag git fetch origin tag V1 # 拉取远程的V1 tag,用于精准获取代码
/**** E 打tag和删除tag以及打release相关命令*/
其他练习:
1.忽略不提交的文件:
在工程根目录下建立.gitignore文件,将要排除的文件或目录 写到.gitignore这个文件中
参考:http://www.cnblogs.com/qlqwjy/p/7468892.html
2.删除本地的索引重新添加索引
先把本地缓存的索引删除(改变成未track状态),然后再提交:
git rm -r --cached .
git add .
更全的git命令参考:http://www.cnblogs.com/qlqwjy/p/7507450.html
本地的master分支和远程的master分支对应,一般在本地自己的分支操作。拿master从远程pull之后,master是最新的代码,将master合并到自己的分支需要提交到远程自己的分支对应的分支。所以最好是在本地master拉下来之后将自己的分支删掉重新从master切分支。
git是在commit之后来监测变化的,所以如果刚开始两个分支都没commit是一样的,切换分支不会出现不同,commit之后切换分支会出现不同。
总结:master与远程的master对应,最好是在一次commit之后将远程对应的分支删除,pull拉下来之后最好把本地的自己的分支删掉,然后从master切出分支,以保证代码是最新的代码。
分支对分支,拉下来之后拉到哪个分支哪个就是最新的,一般拿master拿下来,master一直保持最新的代码,然后从master不停的切分支。也可以拿自己的开发分支拿下来远程的master分支,然后切换到master之后将自己的开发分支合并进去。
在开发过程中,每次添加文件之后要用git add . 添加索引,否则不会提交,每次commit只能提交已经加索引的东西。也可以清楚索引后重新添加:
git rm -r --cached . 删除本地的索引重新添加索引
git add .
git init # 初始化本地git仓库(创建新仓库)
git config --list # 查看本地的配置信息
git config --global user.name "xxx" # 配置用户名
git config --global user.email "xxx@xxx.com" # 配置邮件
git config --global color.ui true # git status等命令自动着色
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
git config --global --unset http.proxy # remove proxy configuration on git
git clone git+ssh://git@192.168.53.168/VT.git # clone远程仓库
git status # 查看当前版本状态(是否修改)
git add xyz # 添加xyz文件至index
git add . # 增加当前子目录下所有更改过的文件至index
git commit -m 'xxx' # 提交
git commit --amend -m 'xxx' # 合并上一次提交(用于反复修改)
git commit -am 'xxx' # 将add和commit合为一步
git rm xxx # 删除index中的文件
git rm -r * # 递归删除
git log # 显示提交日志
git log -1 # 显示1行日志 -n为n行
git log -5
git log --stat # 显示提交日志及相关变动文件
git log -p -m
git show dfb02e6e4f2f7b573337763e5c0013802e392818 # 显示某个提交的详细内容
git show dfb02 # 可只用commitid的前几位
git show HEAD # 显示HEAD提交日志
git show HEAD^ # 显示HEAD的父(上一个版本)的提交日志 ^^为上两个版本 ^5为上5个版本
git tag # 显示已存在的tag
git tag -a v2.0 -m 'xxx' # 增加v2.0的tag
git show v2.0 # 显示v2.0的日志及详细内容
git log v2.0 # 显示v2.0的日志
git diff # 显示所有未添加至index的变更
git diff --cached # 显示所有已添加index但还未commit的变更
git diff HEAD^ # 比较与上一个版本的差异
git diff HEAD -- ./lib # 比较与HEAD版本lib目录的差异
git diff origin/master..master # 比较远程分支master上有本地分支master上没有的
git diff origin/master..master --stat # 只显示差异的文件,不显示具体内容
git remote add origin git+ssh://git@192.168.53.168/VT.git # 增加远程定义(用于push/pull/fetch)
git branch # 显示本地分支
git branch --contains 50089 # 显示包含提交50089的分支
git branch -a # 显示所有分支
git branch -r # 显示所有原创分支
git branch --merged # 显示所有已合并到当前分支的分支
git branch --no-merged # 显示所有未合并到当前分支的分支
git branch -m master master_copy # 本地分支改名
git checkout -b master_copy # 从当前分支创建新分支master_copy并检出
git checkout -b master master_copy # 上面的完整版
git checkout features/performance # 检出已存在的features/performance分支
git checkout --track hotfixes/BJVEP933 # 检出远程分支hotfixes/BJVEP933并创建本地跟踪分支
git checkout v2.0 # 检出版本v2.0
git checkout -b devel origin/develop # 从远程分支develop创建新本地分支devel并检出
git checkout -- README # 检出head版本的README文件(可用于修改错误回退)
git merge origin/master # 合并远程master分支至当前分支
git cherry-pick ff44785404a8e # 合并提交ff44785404a8e的修改
git push origin master # 将当前分支push到远程master分支
git push origin :hotfixes/BJVEP933 # 删除远程仓库的hotfixes/BJVEP933分支
git push --tags # 把所有tag推送到远程仓库
git fetch # 获取所有远程分支(不更新本地分支,另需merge)
git fetch --prune # 获取所有原创分支并清除服务器上已删掉的分支
git pull origin master # 获取远程分支master并merge到当前分支
git mv README README2 # 重命名文件README为README2
git reset --hard HEAD # 将当前版本重置为HEAD(通常用于merge失败回退)
git rebase
git branch -d hotfixes/BJVEP933 # 删除分支hotfixes/BJVEP933(本分支修改已合并到其他分支)
git branch -D hotfixes/BJVEP933 # 强制删除分支hotfixes/BJVEP933
git ls-files # 列出git index包含的文件
git show-branch # 图示当前分支历史
git show-branch --all # 图示所有分支历史
git whatchanged # 显示提交历史对应的文件修改
git revert dfb02e6e4f2f7b573337763e5c0013802e392818 # 撤销提交dfb02e6e4f2f7b573337763e5c0013802e392818
git ls-tree HEAD # 内部命令:显示某个git对象
git rev-parse v2.0 # 内部命令:显示某个ref对于的SHA1 HASH
git reflog # 显示所有提交,包括孤立节点
git show HEAD@{5}
git show master@{yesterday} # 显示master分支昨天的状态
git log --pretty=format:'%h %s' --graph # 图示提交日志
git show HEAD~3
git show -s --pretty=raw 2be7fcb476
git stash # 暂存当前修改,将所有至为HEAD状态
git stash list # 查看所有暂存
git stash show -p stash@{0} # 参考第一次暂存
git stash apply stash@{0} # 应用第一次暂存
git grep "delete from" # 文件中搜索文本“delete from”
git grep -e '#define' --and -e SORT_DIRENT
git gc
git fsck
更全的参考:http://blog.csdn.net/halaoda/article/details/78661334
关于比较两个分支提交历史的不同参考:https://blog.csdn.net/u011240877/article/details/52586664
补充: 关于团队开发基于git fork之后开发发流程如下
团队开发的流程。Fork项目之后拉取代码进行开发。原来是直接在原地址切分支开发、然后合并到主分支,fork之后可能会有点差距。一个简单的fork项目的例子:
比如原主仓库地址:
https://github.com/qiao-zhi/springcloud-config.git
fork一个项目,fork之后会创建一个项目到自己的仓库,拉取自己仓库的项目
-
1 fork一个项目,fork之后会创建一个项目到自己的仓库,拉取自己仓库的项目
git clone https://github.com/qqiaoliqiang/springcloud-config.git
-
2 本地拉取下来:之后查看分支信息,可以看到只有origin的信息
$ git remote -v origin https://github.com/qqiaoliqiang/springcloud-config.git (fetch) origin https://github.com/qqiaoliqiang/springcloud-config.git (push)
- 3 需要使用“git remote add upstream+源项目地址“”的命令增加上游代码库
git remote add upstream https://github.com/qiao-zhi/springcloud-config.git
- 4 再次查看分支信息
$ git remote -v origin https://github.com/qqiaoliqiang/springcloud-config.git (fetch) origin https://github.com/qqiaoliqiang/springcloud-config.git (push) upstream https://github.com/qiao-zhi/springcloud-config.git (fetch) upstream https://github.com/qiao-zhi/springcloud-config.git (push)
- 5 自己修改自己本地的代码,然后推到自己的仓库。也就是origin的仓库。
- 6 Origin仓库发起merge请求到主仓库,主仓库管理员同意后即可合并请求到upstream的仓库。
- 7 如果远程的分支改了,自己需要同步(fetch + merge 或者 直接pull)。 pull之后可以提交代码到自己的仓库,然后自己的仓库向原仓库发起合并请求。通过比较可以看出自己仓库和远程仓库不同的commit信息,以进行合并。
1》拉取代码
git fetch upstream master
2》合并
$ git merge upstream/master Updating 1b51ef2..940a198 Fast-forward config-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
补充:git清除本地记住的账号密码
$ git config --global credential.helper wincred
$ git credential-manager uninstall
然后设置记住账号密码:
git config --global credential.helper store 然后执行一次git pull 命令,输入账号和密码; 之后会自动记住账号和密码
补充: git 修改提交的信息, 已经commit 但是未push 的:
git commit --amend
可以修改已经commit 但是未push 的信息。
补充: git 合并指定的commit 信息
比如A分支的提交信息合并到B分支:
(1) 在A分支用 git log 查看提交记录, 并且记录提交的 commitId (4231a4839ebdac208255ed7ee5a5660d5bf47ee9) (2) 切换到B分支 git checkout B (3) 进行合并。cherry-pick 可以选择多个id 进行合并 git cherry-pick 4231a4839ebdac208255ed7ee5a5660d5bf47ee9