Git: how to reorder a (strictly) commit sequence

I am creating a retrospective project history from zip snapshots. I have already built a long sequence of commit branches from the snapshots that should have been transferred. I added at the end some more “found” snapshots, which should be in different places “in the middle” of the fixation sequence.

I'm trying git rebase -i <startCommit>to reorder snapshots of git. I just exchange a list of orders to choose from. It should just be a case of re-writing commit objects, but preserving the underlying trees is the same (since the snapshots haven't changed).

It appears that rebase, in this case, is still trying to create fixes and have a lot of conflicts, instead of doing a simple rebuild. Is there a more suitable team for this particular case? I have no mergers and only one branch. The entire repo is still very local and private.

+5
source share
3 answers

don't worry about rebase. Create a new branch. If X is a sha1 or treeish commit to use, then:

git checkout X -- .
git add -A
git commit -C X

Repeat all commits in the chronological order you want.

An example, when we cancel the order of the last 5, it does:

git checkout -b temp old_branch~5
git checkout old_branch -- .
git add -A
git commit -C old_branch
git checkout old_branch~1 -- .
git add -A
git commit -C old_branch~1
git checkout old_branch~2 -- .
git add -A
git commit -C old_branch~2
git checkout old_branch~3 -- .
git add -A
git commit -C old_branch~3
git checkout old_branch~4 -- .
git add -A
git commit -C old_branch~4

git push . HEAD:old_branch -f
git checkout old_branch
git branch -d temp

git log -5 # to see the new history

hope this helps.

+3
source

, , " ". , . :

Commit 1

, , :

Commit 1
Commit 2
Commit 3

, , :

Commit 1
Commit 2

Git , git :

  • , "Commit 1"
  • , "Commit 2" "Commit 3" "Commit 1"
  • "Commit 3" "Commit 2"

, :

  • , "Commit 1"
  • "Commit 3" "Commit 2"
  • , "Commit 2" "Commit 3" "Commit 1"

, "Commit 2" , , , , .

, git 2 , , .

0

:

a->b->c->d->e->f

e f - a d

rebase -i, edit , . git , / . , , .

, , , e f, .

0
source

All Articles