# 查看所有配置
$ git config --list
# 用户名和邮箱
user.name=heyan
user.email=[email protected]
# 全局忽略文件
core.excludesfile=C:\Users\heyan\gitignore_global.txt
# 查看指定配置
$ git config user.name
heyan
$ mkdir git_example
$ cd git_example
$ git init
Initialized empty Git repository in E:/test/git_example/.git/
$ git clone [email protected]/xxx/xxx.git [本地目录]
$ git clone -b develop [email protected]:sunfei/develop.git
$ git fetch --all //只是下载代码到本地,不进行合并操作
$ git reset --hard origin/<分支> //把HEAD指向最新下载的版本
$ git pull
当你本地已经有了库,想推送到远程仓库时,需要先创建远程仓库,然后拿到仓库地址,在本地仓库设置远程仓库地址:
# git remote <远程仓库的别名> <远程仓库地址>
$ git remote add origin [email protected]:sunfei/develop.git
# git remote -v 可以展示所有远程分支
$ git remote -v
origin [email protected]:sunfei/develop.git (fetch)
origin [email protected]:sunfei/develop.git (push)
# git remote -show 可以查看远程分支信息
$ git remote show origin
* remote origin
Fetch URL: [email protected]:sunfei/develop.git
Push URL: [email protected]:sunfei/develop.git
HEAD branch: master
Remote branches:
dev-20191224 tracked
dev-20191224-heyan tracked
prod new (next fetch will store in remotes/origin)
test tracked
Local branches configured for 'git pull':
dev-20191224 merges with remote dev-20191224
dev-20191224-heyan merges with remote dev-20191224-heyan
master merges with remote master
master_old merges with remote master_old
Local refs configured for 'git push':
dev-20191224 pushes to dev-20191224 (up to date)
dev-20191224-heyan pushes to dev-20191224-heyan (up to date)
master pushes to master (local out of date)
master_old pushes to master_old (up to date)
格式: git push <远程仓库> <分支名>
移除: git remote rm <远程仓库>
重命名: git remote rename <原来的仓库名称> <新的仓库名称>
git push origin master
$ git status
On branch master
nothing to commit, working tree clean
一般项目中会有一个文件是不需要纳入git版本管理的,比如编译器生成的文件,项目打包后生成的文件等等,为了解决这个问题,git引入了一个忽略文件,
该文件可以放在仓库的任一目录,文件名固定为: .gitignore,看一个java常用的忽略文件配置:
# 忽略Eclipse生成的 .project 和 .classpath 目录
.project
.classpath
#忽略 IDEA 生成的 .idea/ 目录
.idea/
# 忽略打包生成的文件目录
target/
# 忽略所有 iml/class 后缀的文件
*.iml
*.class
git commit 用来将暂存区的文件添加到本地仓库,他有两个常用参数:
有时候我们提交完了才发现漏掉了几个文件没有添加,或者提交信息写错了. 此时, 可以运行带有 --amend 选项的提交命令尝试重新提交:
git commit --amend
例如,你提交后发现忘记了暂存某些需要的修改,可以像下面这样操作:
$ git commit -m 'init'
$ git add .gitignore
$ git commit --amend
最终你只会有一个提交——第二次提交将代替第一次提交的结果.
如果我们编辑了两个文件,想分别做两次提交,结果不小心执行了 git add * 让两个文件都加到了暂存区,则可以使用 git reset HEAD
来取消,或者使用 `git reset --soft <最后一个commit>
撤销对文件的修改:
git checkout -- <文件>
上面的命令会把文件撤销到上次提交时的内容
$ git branch -a
* dev-20191224
dev-20191224-heyan
master
master_old
remotes/origin/HEAD -> origin/master
remotes/origin/dev-20191014
remotes/origin/dev-20191021
remotes/origin/dev-20191028
remotes/origin/dev-20191111
前面有 * 的是你当前所在分支,没有 remotes/origin/*的是本地其他分支,有remotes/origin/*的为远程分支
比如: 当前在master分支,要基于当前分支创建一个release分支,此时创建后当前分支就为release分支
$ git checkout -b release
Switched to a new branch 'release'
使用 git checkout -b <新分支名>
,这个命令相当于下面两个命令合并:
$ git branch release
$ git checkout release
比如从release分支切换到master分支
$ git checkout master
Switched to branch 'master'
# 删除本地分支
$ git branch -d <分支名>
# 删除远程分支
$ git push origin --delete <分支名>
使用 `git merge <要合并的分支名>
$ git merge release
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
可以看到合并时,出现了冲突,可以使用 git diff
查看冲突内容:
$ git diff README.md
diff --cc README.md
index ef600d9,b61de0c..0000000
--- a/README.md
+++ b/README.md
@@@ -1,1 -1,1 +1,5 @@@
++<<<<<<< HEAD
+merge1
++=======
+ merge test
++>>>>>>> release
查看当前分支提交记录,默认做了分页,只展示一页的数据,如果想查询指定条数,则使用:git log -
$ git log
commit 1018dd3f1e1aff00987cb067354a7b62f02599ff (HEAD -> dev-20191224, origin/dev-20191224)
Author: wangnengsheng <[email protected]>
Date: Wed Dec 18 15:43:38 2019 +0800
修复27465 澳门手机号会员消费后未发送短信
commit 1b8266260be93b2b32565fa23114cb1e3dcbbd36
Merge: bab57871 ede65deb
Author: wangnengsheng <[email protected]>
Date: Wed Dec 18 14:19:48 2019 +0800
Merge branch 'dev-20191224' of http://km-git1.kemai.cn/sunfei/develop into dev-20191224
commit bab57871095263705d0fe2ce5ee53d08f97671fa
Author: wangnengsheng <[email protected]>
Date: Wed Dec 18 14:18:53 2019 +0800
修复bug26909 【出品】关联的做法和规格中有相同名字导致出品编辑报错
查找提交记录中改动过的内容:
$ git log -SupdateObjLimitOne
commit bab57871095263705d0fe2ce5ee53d08f97671fa
Author: wangnengsheng <[email protected]>
Date: Wed Dec 18 14:18:53 2019 +0800
修复bug26909 【出品】关联的做法和规格中有相同名字导致出品编辑报错
-p 用来展示提交的内容差异, -1 则用来限制查询的条数为1条
$ git log -p -1
commit bab57871095263705d0fe2ce5ee53d08f97671fa
Author: wangnengsheng <[email protected]>
Date: Wed Dec 18 14:18:53 2019 +0800
修复bug26909 【出品】关联的做法和规格中有相同名字导致出品编辑报错
diff --git a/src/main/java/com/km/controller/restaurant/ItemRestaurantController.java b/src/main/java/com/km/controller/restaurant/ItemRestaurantController.java
index 0ae97999..8b211b4c 100644
Binary files a/src/main/java/com/km/controller/restaurant/ItemRestaurantController.java and b/src/main/java/com/km/controller/restaurant/ItemRestaurantController.java differ
diff --git a/src/main/java/com/km/dao/ItempropertyDao.java b/src/main/java/com/km/dao/ItempropertyDao.java
index 5bacbfb1..8e422ac9 100644
Binary files a/src/main/java/com/km/dao/ItempropertyDao.java and b/src/main/java/com/km/dao/ItempropertyDao.java differ
diff --git a/src/main/java/com/km/dao/xml/ItempropertyDao.xml b/src/main/java/com/km/dao/xml/ItempropertyDao.xml
index 616e1421..af78b1f6 100644
--- a/src/main/java/com/km/dao/xml/ItempropertyDao.xml
+++ b/src/main/java/com/km/dao/xml/ItempropertyDao.xml
@@ -163,6 +163,63 @@
</foreach>
</update>
+ <!-- 修改该对象 只修改一条-->
+ <update id="updateObjLimitOne" parameterType="com.km.pojo.DItemproperty">
+ update itemproperty
+ <set>
+ <if test="flowId!=null and flowId!=''">
+ flowId = #{flowId},
+ </if>
+ <if test="merchantId!=null and merchantId!=''">
+ merchantId = #{merchantId},
+ </if>
+ <if test="itemId!=null and itemId!=''">
+ itemId = #{itemId},
+ </if>
+ <if test="propertyFlowId!=null and propertyFlowId!=''">
+ propertyFlowId = #{propertyFlowId},
+ </if>
+ <if test="propertyPrice!=null">
+ propertyPrice = #{propertyPrice},
+ </if>
+ <if test="tSFlag!=null and tSFlag!=''">
+ tSFlag = #{tSFlag},
+ </if>
+ <if test="deleteFlag!=null and deleteFlag!=''">
+ deleteFlag = #{deleteFlag},
+ </if>
+ <if test="propertyVipPrice!=null">
+ propertyVipPrice = #{propertyVipPrice},
+ </if>
+ <if test="propertyVipPrice2!=null">
+ propertyVipPrice2 = #{propertyVipPrice2},
+ </if>
+ <if test="propertyVipPrice3!=null">
+ propertyVipPrice3 = #{propertyVipPrice3},
+ </if>
+ <if test="specQty!=null">
+ specQty = #{specQty},
+ </if>
+ </set>
+ <where>
+ <if test="merchantId!=null and merchantId!=''">
+ and merchantId = #{merchantId}
+ </if>
+ <if test="flowId!=null and flowId!=''">
+ and flowId = #{flowId}
+ </if>
+ <if test="itemId!=null and itemId!=''">
+ and itemId = #{itemId}
+ </if>
+ <if test="propertyFlowId!=null and propertyFlowId!=''">
+ and propertyFlowId = #{propertyFlowId}
+ </if>
+ <if test="branchId!=null and branchId!=''">
+ and branchId = #{branchId}
+ </if>
+ </where>
+ limit 1
+ </update>
<!-- 修改该对象 -->
<update id="updateObj" parameterType="com.km.pojo.DItemproperty">
update itemproperty
@@ -526,6 +583,7 @@
</update>
+
<select id="getItemPropertyList" parameterType="map" resultType="com.km.pojo.DItemproperty" flushCache="true"
useCache="false">
select *
diff --git a/src/main/java/com/km/service/IItempropertyService.java b/src/main/java/com/km/service/IItempropertyService.java
index f0db2144..a079af29 100644
Binary files a/src/main/java/com/km/service/IItempropertyService.java and b/src/main/java/com/km/service/IItempropertyService.java differ
diff --git a/src/main/java/com/km/serviceImpl/ItempropertyServiceImpl.java b/src/main/java/com/km/serviceImpl/ItempropertyServiceImpl.java
index d671ac28..d6b1ee63 100644
Binary files a/src/main/java/com/km/serviceImpl/ItempropertyServiceImpl.java and b/src/main/java/com/km/serviceImpl/ItempropertyServiceImpl.java differ
简化查询的提交内容,只能看到修改文件新增,修改的行数
$ git log --stat
commit 1018dd3f1e1aff00987cb067354a7b62f02599ff (HEAD -> dev-20191224, origin/dev-20191224)
Author: wangnengsheng <[email protected]>
Date: Wed Dec 18 15:43:38 2019 +0800
修复27465 澳门手机号会员消费后未发送短信
.../com/km/controller/sync/VipSyncController.java | Bin 167517 -> 167522 bytes
.../com/km/serviceImpl/VipBalanceServiceImpl.java | Bin 60779 -> 60832 bytes
2 files changed, 0 insertions(+), 0 deletions(-)
commit 1b8266260be93b2b32565fa23114cb1e3dcbbd36
Merge: bab57871 ede65deb
Author: wangnengsheng <[email protected]>
Date: Wed Dec 18 14:19:48 2019 +0800
Merge branch 'dev-20191224' of http://km-git1.kemai.cn/sunfei/develop into dev-20191224
commit bab57871095263705d0fe2ce5ee53d08f97671fa
Author: wangnengsheng <[email protected]>
Date: Wed Dec 18 14:18:53 2019 +0800
修复bug26909 【出品】关联的做法和规格中有相同名字导致出品编辑报错
.../restaurant/ItemRestaurantController.java | Bin 166556 -> 167779 bytes
src/main/java/com/km/dao/ItempropertyDao.java | Bin 1630 -> 1774 bytes
src/main/java/com/km/dao/xml/ItempropertyDao.xml | 58 +++++++++++++++++++++
.../java/com/km/service/IItempropertyService.java | Bin 2000 -> 2058 bytes
.../km/serviceImpl/ItempropertyServiceImpl.java | Bin 7174 -> 7327 bytes
5 files changed, 58 insertions(+)
commit ede65deb729a2b721305d4efc51f6fa972172d18
这个选项可以指定使用不同于默认格式的方式展示提交历史。 这个选项有一些内建的子选项供你使用。 比如用 oneline 将每个提交放在一行显示,查看的提交数很大时非常有用。 另外还有 short,full 和 fuller 可以用,展示的信息或多或少有些不同
–pretty=oneline 展示提交的commit内容
$ git log --pretty=oneline -3
1018dd3f1e1aff00987cb067354a7b62f02599ff (HEAD -> dev-20191224, origin/dev-20191224) 修复27465 澳门手机号会员消费后未发送短信
1b8266260be93b2b32565fa23114cb1e3dcbbd36 Merge branch 'dev-20191224' of http://km-git1.kemai.cn/sunfei/develop into dev-20191224
bab57871095263705d0fe2ce5ee53d08f97671fa 修复bug26909 【出品】关联的做法和规格中有相同名字导致出品编辑报错
–pretty=short 展示提交的commit内容以及作者
$ git log --pretty=short -3
commit 1018dd3f1e1aff00987cb067354a7b62f02599ff (HEAD -> dev-20191224, origin/dev-20191224)
Author: wangnengsheng <[email protected]>
修复27465 澳门手机号会员消费后未发送短信
commit 1b8266260be93b2b32565fa23114cb1e3dcbbd36
Merge: bab57871 ede65deb
Author: wangnengsheng <[email protected]>
Merge branch 'dev-20191224' of http://km-git1.kemai.cn/sunfei/develop into dev-20191224
commit bab57871095263705d0fe2ce5ee53d08f97671fa
Author: wangnengsheng <[email protected]>
修复bug26909 【出品】关联的做法和规格中有相同名字导致出品编辑报错
–pretty=full 展示提交的commit内容以及作者和提交者
$ git log --pretty=full -3
commit 1018dd3f1e1aff00987cb067354a7b62f02599ff (HEAD -> dev-20191224, origin/dev-20191224)
Author: wangnengsheng <[email protected]>
Commit: wangnengsheng <[email protected]>
修复27465 澳门手机号会员消费后未发送短信
commit 1b8266260be93b2b32565fa23114cb1e3dcbbd36
Merge: bab57871 ede65deb
Author: wangnengsheng <[email protected]>
Commit: wangnengsheng <[email protected]>
Merge branch 'dev-20191224' of http://km-git1.kemai.cn/sunfei/develop into dev-20191224
commit bab57871095263705d0fe2ce5ee53d08f97671fa
Author: wangnengsheng <[email protected]>
Commit: wangnengsheng <[email protected]>
修复bug26909 【出品】关联的做法和规格中有相同名字导致出品编辑报错
–pretty=fuller 展示提交的commit内容以及作者,提交者,作者编写时间和提交者时间
$ git log --pretty=fuller -3
commit 1018dd3f1e1aff00987cb067354a7b62f02599ff (HEAD -> dev-20191224, origin/dev-20191224)
Author: wangnengsheng <[email protected]>
AuthorDate: Wed Dec 18 15:43:38 2019 +0800
Commit: wangnengsheng <[email protected]>
CommitDate: Wed Dec 18 15:43:38 2019 +0800
修复27465 澳门手机号会员消费后未发送短信
commit 1b8266260be93b2b32565fa23114cb1e3dcbbd36
Merge: bab57871 ede65deb
Author: wangnengsheng <[email protected]>
AuthorDate: Wed Dec 18 14:19:48 2019 +0800
Commit: wangnengsheng <[email protected]>
CommitDate: Wed Dec 18 14:19:48 2019 +0800
Merge branch 'dev-20191224' of http://km-git1.kemai.cn/sunfei/develop into dev-20191224
commit bab57871095263705d0fe2ce5ee53d08f97671fa
Author: wangnengsheng <[email protected]>
AuthorDate: Wed Dec 18 14:18:53 2019 +0800
Commit: wangnengsheng <[email protected]>
CommitDate: Wed Dec 18 14:18:53 2019 +0800
修复bug26909 【出品】关联的做法和规格中有相同名字导致出品编辑报错
可以定制要显示的记录格式
$ git log --pretty=format:"%h - %an, %ar : %s" -3
1018dd3f - wangnengsheng, 19 hours ago : 修复27465 澳门手机号会员消费后未发送短信
1b826626 - wangnengsheng, 20 hours ago : Merge branch 'dev-20191224' of http://km-git1.kemai.cn/sunfei/develop into dev-20191224
bab57871 - wangnengsheng, 20 hours ago : 修复bug26909 【出品】关联的做法和规格中有相同名字导致出品编辑报错
git log --pretty=format 常用的选项
项目每次上线的时候,一般需要打一个标签,记录当前上线发布的是哪次提交,标签可以记录一些内容.
git tag
轻量标签(lightweight) 与附注标签(annotated).
一个轻量标签很像一个不会改变的分支——它只是一个特定提交的引用.
附注标签是存储在 Git 数据库中的一个完整对象.它们是可以被校验的;其中包含打标签者的名字、电子邮件地址、日期时间;还有一个标签信息;并且可以使用 GNU Privacy Guard (GPG)签名与验证. 通常建议创建附注标签,这样你可以拥有以上所有信息
$ git tag -a v1.0 -m "first tag"
查看标签内容:
$ git show v1.0
tag v1.0
Tagger: heyan <[email protected]>
Date: Thu Dec 19 10:57:43 2019 +0800
first tag
commit c3cc71167b303e53a5573cc3a495633621eca8e0 (HEAD -> master, tag: v1.0)
Author: heyan <[email protected]>
Date: Thu Dec 19 10:57:15 2019 +0800
init
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ea37ec4
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+project init
直接使用 git tag <标签名>:
$ git tag v1.1
# 查看标签内容
$ git show v1.1
commit 575c13db14b978413ca1ba9a35400f25df92df75 (HEAD -> master, tag: v1.1)
Author: heyan <[email protected]>
Date: Thu Dec 19 11:00:10 2019 +0800
edit README.md
diff --git a/README.md b/README.md
index ea37ec4..9daeafb 100644
--- a/README.md
+++ b/README.md
@@ -1 +1 @@
-project init
+test
git tag -a v1.2 -m “标签内容”
git tag -a v1.2 -m "测试历史标签" d937de75
默认创建的标签执行 git push 是不会被推送到远程仓库的,必须要单独推送:
# 推送某个标签到远程仓库
$ git push origin v1.1
# 推送所有标签到远程仓库
$ git push origin --tags
# 删除本地标签
$ git tag -d v1.1
# 推送到远程仓库
$ git push origin:refs/tags/v1.1
可以使用 git checkout
命令,切换后如果做了新的提交,可能会产生一些副作用,尽量不要在分支上提交代码
# git checkout -b <新分支名称> <标签名>
$ git checkout -b test v1.1