当前位置:   article > 正文

Git修改历史提交_git修改提交历史

git修改提交历史

项目分支

Git 分支

分支名功能
Master功能完整且随时可以发布到线上进行部署的正式发布分支。基于tag进行标记,方便快速回退。
Hotfix基于master分支的fork而来,修复线上bug,快速打补丁用的。bug修复完成后,需合并到master分支和develop分支。
Release发布分支,准master分支(功能开发完了,但还有部分bug),待修复完全后合并到master分支,并打tag
Develop功能的集成分支。feature新功能开发都是基于这个分支fork进行。
Feature是功能分支,从Develop分支fork而来。新功能开发完成后,合并到Develop分支。Feature分支不能直接合并到master分支上

1. Git修改历史提交

# 1.修改最新commit msg
git commit --amend

# 2.修改历史第一条comimt msg
git rebase -i --root  

#3.修改第一条之后的commit信息
git stash  #将当前的修改用stash存储一下,后面解决完之后再释放出来
git log
git rebase -i e186c75c5431a6  #这种方法只能修改第一次之后的。 -i 就是 --interactive
git commit --amend #此时将有问题的提交前的pick改为edit或者reword,修改commit信息
        # p, pick = use commit  使用提交(即保留它,不做修改)
        # r, reword = use commit, but edit the commit message 使用提交,但编辑提交的日志消息
        # e, edit = use commit, but stop for amending 使用提交,但停下来修改(就是要修改提交的内容)
        # s, squash = use commit, but meld into previous commit 使用提交,但融入此前的提交(就是与在此之前一个提交合并)
        # f, fixup = like "squash", but discard this commit's log message 类似于squash,但是丢弃此提交的日志消息
        # x, exec = run command (the rest of the line) using shell 运行shell命令
        # d, drop = remove commit 删除提交
vim x.cpp
git add x.cpp
git commit --amend
git rebase --continue #逐步前进到最新的提交位置
git stash pop  #最后将stash存储的内容释放出来,继续工作
git push --force-with-lease origin #强制推送旧提交
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

2. 日志

git log --stat -1
git log --stat --pretty=oneline -3
git log --oneline --decorate -6  #显示引用(分支、tag等) 
git log --pretty=fuller --decorate -2
  • 1
  • 2
  • 3
  • 4

3. 提交日志

git commit --amend -m "xxxx"
git commit -C C  #提交说明重用C提交的提交说明。
  • 1
  • 2

4. 清理 git 记录

	git reflog # 引用日志:记录了HEAD、分支和标签引用的所有操作
 # 很多条 git commit --amend 记录,怎么办?想删除清理干净,用下面命令:
	git reflog expire --expire=now       # 清理当前分支中不再活动的条目
	git reflog expire --expire=now --all #清理所有分支
	git gc --prune=now                   #清理垃圾
  • 1
  • 2
  • 3
  • 4
  • 5

5. 打tag

git tag F
git tag E HEAD^
git tag D HEAD^^
git tag C HEAD^^^
git tag B HEAD~4
git tag A HEAD~5
git tag -d tag_name   #删除某tag点
git checkout tag_name #切换到某tag点
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

6. git clone

alias wget='wget --no-check-certificate'
alias gcl='git clone --recursive --recurse-submodules'
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/483671
推荐阅读
相关标签
  

闽ICP备14008679号