我如何使用Git rebase重新排序/合并提交? [英] How can I reorder/combine commits using Git rebase?

查看:336
本文介绍了我如何使用Git rebase重新排序/合并提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想完成以下任务:

[其中一些在我开始弄乱rebase之前就OK了] [/ b]


  • 移动顶部提交(Removed extraneous .. 。)到分支之前(右上方修复#226)。

  • 结合'twist / main'分支中的两个提交。逗号和Moved loaded ...应该是相同的提交,并且我根本不需要逗号提交信息。
  • 合并新组合的Move loaded提交到'备份'分支,并摆脱扭曲。

  • 将'master'移动到它现在说'备份'的位置。那remote / originins / master标记是什么意思?





我意识到这是要求很多,但请包括e实际的GIT命令。



我不介意自己阅读和尝试,但由于结果与我预期的结果不匹配,我真的不想意外地销毁任何提交。 首先,重新命令备份提交。

 #安全性,如果您的gitk快照准确无误,应该是无效的
git checkout备份

#临时分支
git分支备份 - 保存备份

#将顶部提交移至'修正#226:
git rebase - 起源/主HEAD ^

#回到已保存的分支的父母(即没有移动的提交)
git reset --hard backup-save ^

#重新移到提交的提交(HEAD @ {1}是HEAD是1步
#前的位置)
git rebase HEAD @ {1}

#不再需要保存的分支(尽管您可能希望
#将其保留为以防万一)。这会删除它:
git branch -D backup-save

,忽略顶部提交消息。

  git checkout twist 

git reset --soft HEAD ^

#只需重新保存提交消息,或者跳过
#editor步骤:git commit --amend -C HEAD
git commit --amend

twist 分支合并到备份,删除twist分支。

  git checkout backup 
git merge twist
git branch -d twist

移动 master 。有多种奇特的方式,但这是最简单的。我假设你想 master 指向编辑的备份位置,而不是原来的位置。

  git checkout master 
git reset --hard backup

remote / origins / master 是远程跟踪分支,并告诉您<$ c $的分支指针c> master 远程仓库 origin 中的分支是,或者说当你上次抓取,推入或拉出时的分支。


After quite a few hours playing with rebase, the repo still looks different from what I need:

I would like to accomplish the following tasks:
[some of which were OK before I started messing with rebase :( ]

  • Move The top commit ("Removed extraneous...") to before the branch off (Right above "fix for #226").
  • Combine the two commits that are in the 'twist/main' branch.   "comma" and "Moved loaded..." should be the same commit, and I don't need the commit message of "comma" at all.
  • Merge the newly combined "Move loaded" commit into the 'backup' branch, and get rid of 'twist'.
  • Move 'master' to where it now says 'backup'.
  • What does that "remote/origins/master" tag mean?

I realize that this is asking a lot, but please include actual GIT commands.

I don't mind reading and trying on my own, but am a bit confused by the results not matching what I would've expected, and I really don't want to accidentally destroy any commits.

解决方案

First, re-ordering the backup commits.

# Safety, should be a no-op if your gitk snapshot is accurate
git checkout backup

# Temporary branch
git branch backup-save backup

# Move top commit onto 'Fix for #226:
git rebase --onto origin/master HEAD^

# Go back to saved branch's parent (i.e. without the moved commit)
git reset --hard backup-save^

# Rebase onto the moved commit (HEAD@{1} is where HEAD was 1 step
# ago i.e. before the reset.)
git rebase HEAD@{1}

# Don't need the saved branch any more (although you might want
# to keep it for a bit just in case). This deletes it:
git branch -D backup-save

Combine the two commits on twist, ignoring the top commit message.

git checkout twist

git reset --soft HEAD^

# Just re-save the commit message, alternatively to skip the
# editor step do this: git commit --amend -C HEAD
git commit --amend

Merge the twist branch into backup, remove the twist branch.

git checkout backup
git merge twist
git branch -d twist

Move master. There are multiple fancy ways, but this is simplest. I'm assuming that you want master to point to the edited backup position and not where it originally was.

git checkout master
git reset --hard backup

remote/origins/master is the remote tracking branch and tells you where the branch pointer for the master branch in the remote repository origin is, or rather was when you last fetched, pushed or pulled.

这篇关于我如何使用Git rebase重新排序/合并提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆