一个git存储库中的两个并行历史记录 - 导致git rebase问题

时间:2016-06-23 05:20:05

标签: git github version-control git-merge git-rebase

解释

我在October 15, 2015上创建了一个Git repository,这样我就可以在大约两年内上大学时获得一些代码组合。目前我正在学习如何在Udemy的帮助下使用python进行编程,但是一旦完成该课程,我计划学习C++然后Php 。但显然,除了这一点之外,这就是全部。

所以今天(June 22, 2016)我在我的Git存储库中注意到,因为我从我正在做的一个教程中推送了一些代码,然后恰好运行git log来查看我的所有提交并注意到这样的事情:

git commit tree

所以从我的read开始,我从这个发现中收集的信息是我合并了一些错误的东西,因此我最终得到的东西看起来像上面的图像。

我的下一步是看看我是否可以使用git rebase -i --root命令删除蓝色框中标记的所有提交(在上图中)。哪个当然是好的,直到它达到提交15(约),然后它吐出一个看起来像这样的错误消息:

2nd error message

所以在这一点上,我只是通过运行git rebase --skip来跳过该提交。所以大约两个提交时间(正在排队):

1st error message

所以,当然,我运行git rebase --skip并让其完成其余的提交。

一旦完成,我就跑git rebase --abort,因为它跳过了这两个提交。在发生这一切之后,我的下一步是在互联网上搜索答案。我能找到的唯一好答案之一是here。然后我跟着回答:

  

我建议您先尝试展平历史记录,以摆脱并行历史记录,并删除合并提交。然后,一旦你有一个严格的线性历史记录,你可以设置重写历史记录以删除所有的调试流失。

唯一的问题是我无法弄清楚如何删除并行历史记录和/或删除合并提交,因为当我运行git rebase -i --root时,我得到类似这样的内容:

pick 9140277 Initial commit
pick 95b2f3b Made some minor changes to the code to increase usability
pick d83b165 Converts the folder to a .tar.bz2 and then deletes the folder
pick 3b755b3 Removed some blank lines at the bottom of the file
pick e2f2e3e Added the feature to remove files/folders that are older than a certain age
pick 86b1115 Finished the backup final ftp script for now
pick bfbbcd4 Removed text from a variable
pick 2a7cacd Fixed some minor bugs in the code
pick a943277 Added some new fetures to the script
pick b31bf66 Removed some unnecessary lines of code
pick cc2c9f7 Added Countdown Timers and other help to the portfolio
pick f443919 Fixed a few if statements
pick d6588a0 Everything is in working order
pick f8cc756 Renamed some of the files
pick 6a859f6 Rename backup final ftp.py to backup ftp v.4 (final).py
pick 2dcdae3 Deleted an unneeded folder
pick 0c10370 Added 'Lecture 14 Numbers'
pick 5358b32 Added 'Remove Numbers v.1.py'
pick 8b95691 Reorganized the repository
pick 250f94b Added 'Lecture 16 Strings'
pick 6ebfd31 Changed the numbering of the files
pick 1f275e4 Added 'Lecture 19 Print Formatting'
pick b7d6608 Initial commit
pick 6718968 Made some minor changes to the code to increase usability
pick c2c58c3 Converts the folder to a .tar.bz2 and then deletes the folder
pick 19a495f Removed some blank lines at the bottom of the file
pick c5687a3 Added the feature to remove files/folders that are older than a certain age
pick 93e9742 Finished the backup final ftp script for now
pick 589251c Removed text from a variable
pick 4a7f2d1 Fixed some minor bugs in the code
pick 4172115 Added some new fetures to the script
pick 2377980 Removed some unnecessary lines of code
pick e183900 Added Countdown Timers and other help to the portfolio
pick dfc9747 Fixed a few if statements
pick 0fa9983 Everything is in working order
pick 09abfd7 Renamed some of the files
pick 051dae3 Rename backup final ftp.py to backup ftp v.4 (final).py
pick bac2105 Deleted an unneeded folder
pick e35b6ba Added 'Lecture 14 Numbers'
pick 60b17e4 Added 'Remove Numbers v.1.py'
pick c654494 Reorganized the repository
pick 16e17be Added 'Lecture 16 Strings'
pick 3f37ca3 Changed the numbering of the files
pick ab99b1c Added 'Lecture 19 Print Formatting'
pick 5ea99f2 Added 'Lecture 21 Lists'
pick b8dba98 Reorganized/Fixed all of the code/comments on all of the lectures that I have done up to this point
pick ae50e5b Added 'Lecture 23 Dictionaries'
pick 3306d23 Added 'Lecture 25 Tuples'
pick 36e22b5 Added 'Lecture 26 Files'
pick 2fd3983 Removed a gitignore specifier from the .gitignore file

唯一的问题是我根本没有看到合并,假设看起来像Merge branch 'master' of github.com:Lowe-Man/Portfolio

我保证的最后一个问题。如何使红线消失,绿色线条以及该蓝线的那一小部分使其成为下图中的完整线性历史记录:

linear history

非常感谢任何帮助。 谢谢, 亚历

1 个答案:

答案 0 :(得分:1)

可以省略合并提交。你可以试试git rebase --onto ab99b1c 5ea99f2^ origin/master。完成之后,HEAD就是您想要的,但它可能处于分离的HEAD状态。

更新:为了简化案例,

A--B--M--D--E
           /
O----P

希望预览看起来没问题(M是B和P的合并提交)。你想要删除O P和M,并保持A B D E。

git rebase --onto B M E

现在它就像A-B-D'-E'

更新2:简化其他情况,

A-B----M-D
    \        /
     C---

C来自A并将B合并为M.如果要将C移动到行AD,

git rebase --onto B C^ D

现在你得到A-B-C'-D'。 M是合并提交,已被删除。

更新3:使用git resetgit cherry-pick在第二次更新中完成工作。

git reset B --hard
#now we get A-B

git cherry pick C D
#now we get A-B-C'-D'