Inserting an ignored commit between two commits

I have a clone of a public git repository. Simplified, commits (AD) look like this:

   +->D
   |
A->B->C

      

Writes A and B already in the public repo. I added commit C to the clone, which includes significant coding changes as well as significant feature changes. I later decided I wanted to add commit D to the clone, which only fixes the standard coding issues in commit B.

I would like to reorder commit C to come after commit D so that everything looks like this:

A->B->D->C

      

Since I've already made changes to the default encoding of both commits, I would like to tell git to accept commit C as-is without merging. I couldn't figure out how to do this. Can anyone suggest a correct approach?

I thought git-rebase with our "our" merge strategy would do the trick, but I had no luck with that.

+3


source to share


3 answers


git checkout C
git reset --soft D
git commit

      

should be enough. git reset --soft

just dumps what git thinks is the "current" commit, without any changes. This way your index and worktree will still be exactly as they were in C

, and you can commit this without any further changes.



Please note that nothing in these commands will result in any merges or automatic conflict resolution. This means that if any part D

that is no longer a part C

, it will effectively restore those changes D

. You stated that this is not a case that D

just contains bits C

, so it shouldn't be a problem.

+3


source


I am using SourceTree as GUI for GIT Assuming C commit is master branch

  • Checkout commit D as "temp"
  • Select all files in commit C, right click and "reset to commit"
  • Unexpected changes should now show changes to your function.
  • Commit your changes as E
  • Delete branch "master"
  • Marking "temp" as "master"


You get A-> B-> D-> E where E - C with no change in D.

+1


source


I think it is as simple as:

git checkout D
git cherry-pick <commitIDofC>

      

Resolve any missing conflicts. The content of the commit will not be exactly the same because they simply cannot be, the history is in B

, and the history after B->D

cannot be the same, so if you touch the same areas of the code, t will be the same.

Please try this and let me know.

Greetings.

+1


source







All Articles