git rebase 与提交纪录重写

版权声明:欢迎转载,转载请说明出处https://csdn.yanxml.com。大数据Github项目地址https://github.com/SeanYanxml/bigdata。 https://blog.csdn.net/u010416101/article/details/84559005

前言

千万不要在主分支和远端分支有提交纪录的时候使用git rebase命令。

前段时间有这样一个需求,在不改变大体上git提交树的基础上,修改某个git提交节点的提交内容。查询到发现git rebase命令。

主要用处:

  • 更改历史节点;
  • 更改历史提交纪录,合并本地未提交的提交纪录;

操作命令

  • 确保当前节点头在本地某个节点,并且没有任何提交纪录。
  • 通过git rebase -i <节点id>
localhost:bigdata Sean$ git rebase -i 634615a

pick 7fa0c23 Update the struct of the project zk-demo.
pick 5d224e6 ZK Demos 2: subscribe.
pick f594ca8 The lock demo of zk.
pick 876f182 Distribute service of zk.
pick 449057a Half of the code of the zk demo balance .
pick 5b98df9 The demo of the zk demos - balance.
pick adfe4c3 The queue demo of zk.
pick 1a97825 Kafka consumer & provider demo.
pick 8e37f6a Spark Streaming & Mongodb Init.
pick 29b9241 Update last commit.
pick f370aa9 Update the kafka security button on.

# Rebase 634615a..f370aa9 onto 634615a (11 commands)
#
# Commands:
# 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
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
"~/Documents/Gitrep/bigdata/.git/rebase-merge/git-rebase-todo" 30L, 1116C

pick:保留该commit(缩写:p)
reword:保留该commit,但我需要修改该commit的注释(缩写:r)
edit:保留该commit, 但我要停下来修改该提交(不仅仅修改注释)(缩写:e)
squash:将该commit和前一个commit合并(缩写:s)
fixup:将该commit和前一个commit合并,但我不要保留该提交的注释信息(缩写:f)
exec:执行shell命令(缩写:x)
drop:我要丢弃该commit(缩写:d)

  • 根据本地修改git add filename(修改/新建)/git rm filename(删除),随后进行保存。其中edit会将修改定位到某个需要修改的节点位置。
  • 成功保存。Successfully rebased and updated refs/heads/master.

操作记录

localhost:bigdata Sean$ git rebase -i d70e471
Successfully rebased and updated refs/heads/master.
localhost:bigdata Sean$ git rebase -i bdb4997
Successfully rebased and updated refs/heads/master.
localhost:bigdata Sean$ git rebase -i e113b0a
Could not execute editor
localhost:bigdata Sean$ git rebase -i e113b0a
Stopped at bdb4997... The action to simulate the vote for leader.
You can amend the commit now, with

	git commit --amend

Once you are satisfied with your changes, run

	git rebase --continue

localhost:bigdata Sean$ git rebase --continue
Successfully rebased and updated refs/heads/master.
localhost:bigdata Sean$ git rebase -i e113b0a
Stopped at deffb2a... Update for stress test for flume-kafka-consmer. Function: Get the data from kafka & data logic handle.
You can amend the commit now, with

	git commit --amend

Once you are satisfied with your changes, run

	git rebase --continue

pick bdb4997 The action to simulate the vote for leader.
localhost:bigdata Sean$ git commit --amend
[detached HEAD 5ab265a] Update for stress test for flume-kafka-consmer. Function: Get the data from kafka & data logic handle.
 Date: Mon Jun 25 18:29:37 2018 +0800
 8 files changed, 262 insertions(+), 1 deletion(-)
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/Main.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/config/DBConfig.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/config/StressEnvConfig.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/consumer/KafkaStressConsumer.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/dao/DataHandleDao.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/util/RegexUtil.java
localhost:bigdata Sean$ ls
README.md	apps		kafka		mongodb		pom.xml		redis		spark		spark-redis	spark-streaming	word2vec	zookeeper
localhost:bigdata Sean$ git add kafka/src/main/java/com/yanxml/kafka/stresstest/consumer/KafkaStressConsumer.java
localhost:bigdata Sean$ git commit --amend
[detached HEAD 46ec8f6] Update for stress test for flume-kafka-consmer. Function: Get the data from kafka & data logic handle.
 Date: Mon Jun 25 18:29:37 2018 +0800
 8 files changed, 262 insertions(+), 1 deletion(-)
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/Main.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/config/DBConfig.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/config/StressEnvConfig.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/consumer/KafkaStressConsumer.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/dao/DataHandleDao.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/util/RegexUtil.java
localhost:bigdata Sean$ git rebase --continue
error: could not apply d70e471... Stress count demo of kafka.

When you have resolved this problem, run "git rebase --continue".
pick bdb4997 The action to simulate the vote for leader.
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
Could not apply d70e4718dbe1b4d6a1b1592b26fda3f38b6cbf24... Stress count demo of kafka.
localhost:bigdata Sean$ git rebase --continue
kafka/src/main/java/com/yanxml/kafka/stresstest/consumer/KafkaStressConsumer.java: needs merge
You must edit all merge conflicts and then
mark them as resolved using git add
localhost:bigdata Sean$ git rebase --continue
kafka/src/main/java/com/yanxml/kafka/stresstest/consumer/KafkaStressConsumer.java: needs merge
You must edit all merge conflicts and then
mark them as resolved using git add
localhost:bigdata Sean$ git rebase --continue
[detached HEAD 7aacbb3] Stress count demo of kafka.
 6 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/Test.java
Successfully rebased and updated refs/heads/master.
localhost:bigdata Sean$ git rebase -i e113b0a
Stopped at 46ec8f6... Update for stress test for flume-kafka-consmer. Function: Get the data from kafka & data logic handle.
You can amend the commit now, with

	git commit --amend

Once you are satisfied with your changes, run

	git rebase --continue

localhost:bigdata Sean$ git add kafka/src/main/java/com/yanxml/kafka/stresstest/consumer/dao/DataHandleDao.java
fatal: pathspec 'kafka/src/main/java/com/yanxml/kafka/stresstest/consumer/dao/DataHandleDao.java' did not match any files
localhost:bigdata Sean$ git add kafka/src/main/java/com/yanxml/kafka/stresstest/dao/DataHandleDao.java
localhost:bigdata Sean$ git commit --amend
[detached HEAD ed2ffda] Update for stress test for flume-kafka-consmer. Function: Get the data from kafka & data logic handle.
 Date: Mon Jun 25 18:29:37 2018 +0800
 8 files changed, 262 insertions(+), 1 deletion(-)
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/Main.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/config/DBConfig.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/config/StressEnvConfig.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/consumer/KafkaStressConsumer.java
pick bdb4997 The action to simulate the vote for leader.
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/dao/DataHandleDao.java
 create mode 100644 kafka/src/main/java/com/yanxml/kafka/stresstest/util/RegexUtil.java
pick bdb4997 The action to simulate the vote for leader.
localhost:bigdata Sean$ git rebase --continue
Successfully rebased and updated refs/heads/master.
localhost:bigdata Sean$ git rebase -i e113b0a
Could not execute editor
localhost:bigdata Sean$ git rebase -i e113b0a
Stopped at f3b3b0f... The deploy of redis.
You can amend the commit now, with

	git commit --amend

Once you are satisfied with your changes, run

	git rebase --continue

localhost:bigdata Sean$ git commit --amend
[detached HEAD b8b5ace] The deploy of redis.
 Date: Wed Jul 18 14:23:00 2018 +0800
 9 files changed, 2056 insertions(+), 1 deletion(-)
 create mode 100644 redis/deploy/cluster/7000/redis.conf
 create mode 100644 redis/deploy/cluster/ruby lib/Makefile
 create mode 100644 redis/deploy/cluster/ruby lib/zlib-devel-1.2.7-17.el7.x86_64.rpm
 create mode 100644 redis/deploy/cluster/script/start-all.sh
 create mode 100644 redis/deploy/official/redis-common.conf
 create mode 100644 redis/deploy/official/redis.conf
 create mode 100644 redis/deploy/sentinel/sentinel.conf
 create mode 100644 redis/deploy/single/redis.conf
localhost:bigdata Sean$ git rebase --continue
redis/deploy/official/redis-common.conf: needs update
redis/deploy/official/redis.conf: needs update
You must edit all merge conflicts and then
mark them as resolved using git add
localhost:bigdata Sean$ git rebase --continue
redis/deploy/official/redis-common.conf: needs update
redis/deploy/official/redis.conf: needs update
You must edit all merge conflicts and then
mark them as resolved using git add
localhost:bigdata Sean$ git rebase --continue
You have uncommitted changes in your working tree. Please commit them
first and then run 'git rebase --continue' again.
localhost:bigdata Sean$ git rebase --continue
Successfully rebased and updated refs/heads/master.
localhost:bigdata Sean$ git rebase -i e113b0a
Successfully rebased and updated refs/heads/master.
localhost:bigdata Sean$ git rebase -i e113b0a
Stopped at b8b5ace... The deploy of redis.
You can amend the commit now, with

	git commit --amend

Once you are satisfied with your changes, run

	git rebase --continue

localhost:bigdata Sean$ git delete redis⁩ ▸ ⁨deploy⁩ ▸ ⁨official⁩



kafka/src/main/java/com/yanxml/kafka/stresstest/consumer/KafkaStressConsumer.java: needs merge
You must edit all merge conflicts and then
The deploy of redis.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Wed Jul 18 14:23:00 2018 +0800
#
# interactive rebase in progress; onto e113b0a
# Last commands done (3 commands done):
#    pick ed2ffda Update for stress test for flume-kafka-consmer. Function: Get the data from kafka & data logic handle.
#    edit f3b3b0f The deploy of redis.
# Next commands to do (17 remaining commands):
#    pick 30ccf1e The demos of redis.
#    pick 2cd136a Update the annotation of the redis pub/sub .
# You are currently editing a commit while rebasing branch 'master' on 'e113b0a'.
#
# Changes to be committed:
#       modified:   README.md
#       new file:   redis/deploy/cluster/7000/redis.conf
#       new file:   redis/deploy/cluster/ruby lib/Makefile
#       new file:   redis/deploy/cluster/ruby lib/zlib-devel-1.2.7-17.el7.x86_64.rpm
#       new file:   redis/deploy/cluster/script/start-all.sh
#       new file:   redis/deploy/official/redis-common.conf
#       new file:   redis/deploy/official/redis.conf
#       new file:   redis/deploy/sentinel/sentinel.conf
#       new file:   redis/deploy/single/redis.conf
#
# Changes not staged for commit:
#       deleted:    redis/deploy/official/redis-common.conf
#       deleted:    redis/deploy/official/redis.conf

Reference

[1]. 【Git系列】git rebase详解
[2]. 【Git】rebase 用法小结

没有更多推荐了,返回首页