(one more) change git history to add very first commit

I am changing the code of another (not git). I loaded the original, completed my modifications and jumped from the gun and made the modified version my first fixation. It was a mistake, I had to add the source code downloaded as the first commit.

Then, to add insult to the injury, I added the source code as a branch of my first edit .. In other words, now this is a big mess :(

Simply put, what I have is like the blue graph below. C5 is the real source code, C1, C2-C6 are my incremental modifications (C4 is redundant). I'd rather greens be my story.

enter image description here

Any ideas on how to change the story to do this?

Thank you, many,

tricky

+6
source share
1 answer

I did this completely on the command line, but I am going to insert screenshots from SourceTree to illustrate what is happening.

First get the first 7 or 8 digits of the commit identifier (50da9c3) from transaction C5 and add to your clipboard or textedit or something else - you'll need it later

To confirm, here is our initial state:

enter image description here

Here are the steps you need to complete so that you can:

Create a new branch without roots to start the construction, it completes the work with the named base.

git symbolic-ref HEAD refs/heads/base 

Now delete all files and directories from git

 git rm --cached -r . 

Now that all untracked files remove them from the local working directory

 git clean -d --force 

Now create a commit without anything (this will be a commit on which everything will be built).

 git commit --allow-empty -m'Initial Commit' 

Your tree should look like this:

enter image description here

Now the cherry selects c5 commit (what you had on the clipboard)

 git cherry-pick 50da9c3 

enter image description here

Now reinstall the main branch to the base branch

 git rebase --onto base --root master 

enter image description here

Now you can delete the base and c4-c5 branches

 git branch -d base 

enter image description here

 git branch -D c4-c5branch 

enter image description here

Keep in mind that โ€œInitial commitโ€ is an empty commit without files, so don't be fooled. C5 commit is actually the first content-based commit.

+9
source

Source: https://habr.com/ru/post/912800/


All Articles