0 0 0 0


I would like to remove selected commit log entries from a linear commit tree, so that the entries do not show in the commit log.

My commit tree looks something like:


I would like to remove the B and C entries so that they do not show in the commit log, but changes from A to D should be preserved. Maybe by introducing a single commit, so that B and C become BC and the tree looks like.


Or, ideally, after A comes D directly. D' representing changes from A to B, B to C and C to D.


Is this possible? if yes, how?

This is a fairly new project so has no branches as of now, hence no merges as well.

Best Answer:

Just collected all people's answers:(m new to git plz use it for reference only)

git rebase to delete any commits

git log

-first check from which commit you want to rebase

git rebase -i HEAD~1

-Here i want to rebase on the second last commit- commit count starts from '1')
-this will open the command line editor (called vim editor i guess)

Then the screen will look something like this:

pick 0c2236d Added new line.

Rebase 2a1cd65..0c2236d onto 2a1cd65 (1 command)


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


These lines can be re-ordered; they are executed from top to bottom.


If you remove a line here THAT COMMIT WILL BE LOST.


However, if you remove everything, the rebase will be aborted.


Note that empty commits are commented out ~ ~


Here change the first line as per your need (using the commands listed above i.e. 'drop' to remove commit etc.) Once done the editing press ':x' to save and exit editor(this is for vim editor only)

And then

git push

If its showing problem then you need to forcefully push the changes to remote(ITS VERY CRITICAL : dont force push if you are working in team)

git push -f origin

Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs