0

I have a repository with a project in which I work alone, so I have no big issues forcing re-writing of history if really needed. Right now my history repo looks like:

(initial repo)
                                  P   (feature2)
                                 /
          A-B-...-C-D-E-J-K-M-N-O (develop) 
                      |    \ \
                      F-G-H-I-L (feature1)

Where ... is a list of sequential commits I've omited in the graph, and K and M are merge commits from feature1 into develop. The issue is I've found a typo in my .gitignore and I can't really run the project if a clone the repo in another pc right now. The fix was introduced in two commits, N and O and I'd like to move N and O to their right places in time to be able to clone the project in any commit and be workable something like:

(moving the commits)
                                  P   (feature2)
                                 /
          A-N-B-...-C-O-D-E-J-K-M (develop) 
                      |      / /
                      F-G-H-I-L (feature1)

As you can see I would like to retain the merge structure from K, M, etc.

Ideally N should be a fixup of the initital commit A, and O a fixup of commit C:

(after squash/fixup)
                                P   (feature2)
                               /
          A*-B-...-C*-D-E-J-K-M (develop) 
                        |    \ \
                        F-G-H-I-L (feature1)

I've tried both --preserve-merges or -i --rebase-merges as I read related questions on SO and the git docs but have to go end up undoing it because it messes up more.

How would you proceed to achieve this?

40detectives
  • 350
  • 1
  • 3
  • 12
  • I wouldn't attempt this, for a number of reasons. First and foremost, if these branches are already publicly shared, then rewriting their history could cause problems for everyone. Next, there is no easy way to rebase over merge commits without redoing the merges. Git does have a feature where it can try to recreate the merges, but in general I would not trust it. – Tim Biegeleisen Sep 24 '18 at 08:32
  • I've stated that I work alone in the repository, so _I could_. I understand that behind the scenes git rebase replays the commits to create new ones (different hashes), what I want to achieve is the graph topology. – 40detectives Sep 24 '18 at 08:34
  • Second reason: Are you in a position to redo the merge commits? Do you remember what you did? – Tim Biegeleisen Sep 24 '18 at 08:36
  • Mostly yes, but some changes in text files are autogenerated, thats why I was thinking on letting Git recreate the merges with `--preserve-merges` or `--rebase-merges` – 40detectives Sep 24 '18 at 09:38

0 Answers0