美文网首页
git commit (玩转提交)

git commit (玩转提交)

作者: 潘帅次元 | 来源:发表于2017-11-02 22:23 被阅读241次

在团队开发中使用git的常用操作有

git checkout -b local_branch_name origin/master
git add file_name1 file_name2 file_name3...
git commit -m "my commit description"
git push origin branch_name
git checkout test_branch_name
git pull origin test_branch_name
git merge --no-ff local_branch_name
## maybe solve conflicts
git push origin test_branch_name

上面缺陷

这操作完全没有问题,只是在commit的时候,必须保证之前add的文件是在完成功能、修复bug并且可靠运行的的代码,然后提交的那个description就ok。但是往往很难做到可以一次提交,永久运行的效果。
这时候想如果有一种在commit之后还可以吃后悔药该多好啊!或者可以补交修改的文件到上次commit里面而不用再添加其他commit!
ok,git是在某些情况下是完全可以吃后悔药的!

某些情况是指:号外号外,不要在发布分支、稳定分支、多人同时合作的分支进行下面操作!否则,后悔药也不免变成毒药,补交作业沦为给自己补刀,哈哈@_@

git后悔药

  1. 添加修改有问题部分

git add file_name1 file_name2 file_name3 ...

  1. 将撤回提交的SHA-1中的历史记录进行回退,效果是:commit_SHA1_string 之后的所有提交的修改都会撤回到暂存区,与刚add暂存的代码合并。

git reset --soft commit_SHA1_string

  1. 将改变合并为一次提交

git commit -m "my commit description"

  1. push到远程,需要添加一个-f或者--force 参数,表示强制提交

git push origin -f local_branch_name

潘帅操作记录

PS D:\shuaipanCompanyData\git\t8t-prs-pqm>

PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git checkout quoteOrder
Switched to branch 'quoteOrder'
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git status
On branch quoteOrder
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: t8t-prs-pqm-service/src/main/java/t8t/prs/pqm/service/call/MyProjectService.java
modified: t8t-prs-pqm-service/src/main/java/t8t/prs/pqm/service/inner/DosageDetailInnerService.java
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git add .
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git status
On branch quoteOrder
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: t8t-prs-pqm-service/src/main/java/t8t/prs/pqm/service/call/MyProjectService.java
modified: t8t-prs-pqm-service/src/main/java/t8t/prs/pqm/service/inner/DosageDetailInnerService.java
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git commit -m "add method that create quote order items and it's dosage detail"
[quoteOrder 2945dd6] filter invalid date
2 files changed, 39 insertions(+), 11 deletions(-)
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git status
On branch quoteOrder
nothing to commit, working directory clean
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git log -3
commit 2ad83cccde62db6d48ba09dc347272cb1b93c4f7
Author: shuai.pan shuai.pan@corp.to8to.com
Date: Thu Nov 2 21:00:10 2017 +0800

add method that create quote order items and it's dosage detail

commit 45e9f4ea0a1f7cb1ebdcf27887056c4708be1929
Author: shuai.pan shuai.pan@corp.to8to.com
Date: Thu Nov 2 20:59:05 2017 +0800

add method that query unselect unstandard quote order items

commit 8fa6c94a919ae22d2cd7aff86c123cbb33e20c6e
Author: shuai.pan shuai.pan@corp.to8to.com
Date: Wed Nov 1 13:53:35 2017 +0800

change the project node type code of quote
\
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git reset --soft 45e9f4ea0a1f7cb1ebdcf27887056c4708be1929
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git commit -m "add method that query unselect unstandard quote order items"
[quoteOrder 2945dd6] filter invalid date
2 files changed, 39 insertions(+), 11 deletions(-)
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git log -3
commit 45e9f4ea0a1f7cb1ebdcf27887056c4708be1929
Author: shuai.pan shuai.pan@corp.to8to.com
Date: Thu Nov 2 20:59:05 2017 +0800

add method that query unselect unstandard quote order items


commit 8fa6c94a919ae22d2cd7aff86c123cbb33e20c6e
Author: shuai.pan shuai.pan@corp.to8to.com
Date: Wed Nov 1 13:53:35 2017 +0800

change the project node type code of quote

commit 8fa6c94a919ae22d2cd7aff86c123cbb33e20c6e
Author: shuai.pan shuai.pan@corp.to8to.com
Date: Wed Nov 1 13:53:35 2017 +0800

change the project node type code of quote

git补交作业

  1. 添加修改有问题部分

git add file_name1 file_name2 file_name3 ...

  1. 补交操作(切记删除弹出编辑器的所有内容,然后保存,否则会多出一条的提交记录哦)

git commit --amend

本帅操作

PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git add .
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git commit -m "add method that create quote order items and it's dosage detail"
[opt-order 7b51000] add method that create quote order items and it's dosage detail
7 files changed, 295 insertions(+), 9 deletions(-)
create mode 100644 t8t-prs-pqm-service-api/src/main/java/t8t/prs/pqm/entity/dto/QuoteOrderItemSingleCreateDTO.java
create mode 100644 t8t-prs-pqm-service/src/main/java/t8t/prs/pqm/model/QuoteOrderItemCreateMO.java
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git status
On branch opt-order
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: t8t-prs-pqm-service/src/main/java/t8t/prs/pqm/service/QuoteOrderItemService.java

no changes added to commit (use "git add" and/or "git commit -a")
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git add .
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git log -3
commit 2ad83cccde62db6d48ba09dc347272cb1b93c4f7
Author: shuai.pan shuai.pan@corp.to8to.com
Date: Thu Nov 2 21:00:10 2017 +0800

add method that create quote order items and it's dosage detail

commit 45e9f4ea0a1f7cb1ebdcf27887056c4708be1929
Author: shuai.pan shuai.pan@corp.to8to.com
Date: Thu Nov 2 20:59:05 2017 +0800

add method that query unselect unstandard quote order items

PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git commit --amend
Aborting commit due to empty commit message.
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm>
PS D:\shuaipanCompanyData\git\t8t-prs-pqm> git log -4
commit 2ad83cccde62db6d48ba09dc347272cb1b93c4f7
Author: shuai.pan shuai.pan@corp.to8to.com
Date: Thu Nov 2 21:00:10 2017 +0800

add method that create quote order items and it's dosage detail

commit 45e9f4ea0a1f7cb1ebdcf27887056c4708be1929
Author: shuai.pan shuai.pan@corp.to8to.com
Date: Thu Nov 2 20:59:05 2017 +0800

add method that query unselect unstandard quote order items

commit 8fa6c94a919ae22d2cd7aff86c123cbb33e20c6e
Author: shuai.pan shuai.pan@corp.to8to.com
Date: Wed Nov 1 13:53:35 2017 +0800

change the project node type code of quote
\

相关文章

  • git commit (玩转提交)

    在团队开发中使用git的常用操作有 git checkout -b local_branch_name origi...

  • git commit 提交规范(优化)

    git commit 提交模板和规范 Git每次提交代码,都要写 Commit message(提交说明),否则就...

  • git commit message的规范与校验

    git commit message格式 git每次提交代码,都必须写commit message(提交说明),用...

  • Git-简单命令使用

    Git commit -m "" 只会提交添加到缓存区的文件(只提交添加的) git commit -a -m "...

  • git常用命令

    git add . git commit -m "message"提交,其中message是提交的信息。 git ...

  • Git 10更新最后的提交

    更新最后的提交 ======== 命令 git commit -m "commit message" 提交命令 g...

  • git 常用的命令

    git status 检测状态 git add . 提交的代码显示 git commit -m "备注" 提交...

  • commit -a 和 -am的区别

    理论字面解释的话,git commit -m 用于提交暂存区的文件,而 git commit -am 用于提交跟踪...

  • git

    git 提交文件超出限制 方法: 一、git log 找到提交大文件之前的commit例:commit 88798...

  • 关于Git

    首次提交5条 git init .......git 重复提交3条 git add . git commit -m...

网友评论

      本文标题:git commit (玩转提交)

      本文链接:https://www.haomeiwen.com/subject/wniapxtx.html