top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Flatten history in GIT

+1 vote
506 views

I have a (public) "feature" branch that has been kept up-to-date with "master" by regularly merging master back into it. I would now like to get all the changes from feature but not any of the commits. Basically, I want to replay all of feature's commits without creating those commits.

I thought something like

git cherry-pick -n abcd^..feature

should do the trick (while on master, where abcd is the SHA-1 of the commit where feature was created) but I get conflicts.

First, why the conflicts? I have done all the merges so cherry-pick should simply be able to replay them? Second, what is the correct way of doing this?

posted Jul 30, 2013 by Amit Parthsarthi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote
 
Best answer

Wouldn't git merge --squash do what you're looking for? It seems like the only way to not get conflicts trying to cherry pick is if you never had any conflicts while you were merging master into your feature branch. "Evil" merges, where you actually have to change code, even if it's just to resolve conflicts, don't tend to replay correctly.

It seems like this should do it:

% git checkout master

Switched to branch 'master'

% git merge --squash feature

Squash commit -- not updating HEAD Automatic merge went well; stopped before committing as requested

% git commit

git merge --squash will just apply the changes without creating a commit. You can then make any final changes you want to and write your commit message for the feature.

answer Jul 30, 2013 by Majula Joshi
0 votes

Try
% git cherry-pick -n --no-merges --right-only --topo-order --cherry-pick abcd^..feature

answer Jul 30, 2013 by Deepankar Dubey
Similar Questions
+2 votes

I'm working on a project that used to use a proprietary CM system (aka oldCM). At a point in time, the state of the code was frozen and used as the basis for commits in SVN.

What I would like to to do is take the individal commits from the oldCM and place them into git knowing that the time/date stamps won't match. Then I want to do whatever is necessary to setup git so that I can run "svn rebase" to pull in the commits from the SVN repository.

What is the easy way to do this?

0 votes

I want to retrieve the commit history of a given file.What command should I issue? I expect the command like below.

D:GitTest> git show --commit-history test.txt
8194aaa
c419234
...
+2 votes

As you know, I can checkout the Nth checked out branch via this syntax:

$ git checkout @{-N}

Is there a built-in mechanism to get a listing of previously checked out refs? Basically, this would be similar to 'history' command in linux where instead of actual commands, it lists like this:

HEAD@{-1}: master
HEAD@{-2}: topic1
HEAD@{-3}: 3f346e9 (detached)

Seems like reflog should be able to do this, and maybe it can, but I'm not sure. Any tips? I'd be fine making a convenient alias for this if it ends up being a series of piped commands.

+3 votes

My company is upgrading the laptops and so, they're selling the old ones. The problem is, we've been using the old laptops to access remote git repos and the employer would like to clean all possible traces of repo URLs that have been accessed in these laptops. How do I do this? We used Git Bash and Conemu. Will uninstalling Git Bash and Conemu be enough to delete all repo URL history in the laptops? or are these repo URL never been saved to local disk in the first place?

...