Hello. There is the following branch:

* c9ec96c Some Changes in EG proj * 928b5ea Merge branch 'testHDFS' |\ | * 1504e3f Redact Task | * a9dffca Add xmlResult | * 82cd8fb EGp with MetaCode | * db93620 Add EG progect to test * | 536029f Redact Task * | 44cc081 Add xmlResult * | 370584a EGp with MetaCode * | 96c5388 Add EG progect to test |/ * 765ca4c v5HDFS * 5da3f2a v4HDFS * cedc686 v3HDFS * 28d0e1a v2HDFS * a6f9d63 v1HDFS * e5f373a v3 * 708e3b6 v2 * c89f76a First commit 

A branch from 765ca4c appeared after an attempt to rewrite the e-mail of the author of commits. Then merge of two identical kommit followed (probably in time did not merge all changes with github). It is necessary to remove the duplicate branch.

There were the following attempts to rectify the situation:

  1. git rebase --onto c9ec96c 536029f as advised here . Result:

    First, rewinding head to replay your work on top of it ...

    Fast-forwarded HEAD to c9ec96c.

  2. git reset --hard 1504e3f remove the commit altogether (considering that this can lead to disastrous consequences)

UPD: Tried a method from @alexander barakin, here's what happened:

  1. git checkout c9ec96с
  2. git rebase -i 765ca4c

     pick 96c5388 Add EG progect to test pick 370584a EGp with MetaCode pick 44cc081 Add xmlResult pick 536029f Redact Task pick db93620 Add EG progect to test pick 82cd8fb EGp with MetaCode pick a9dffca Add xmlResult pick 1504e3f Redact Task pick c9ec96c Some Changes in EG proj 

    Then:

     pick 96c5388 Add EG progect to test pick 370584a EGp with MetaCode pick 44cc081 Add xmlResult pick 536029f Redact Task pick c9ec96c Some Changes in EG proj :x 

    Successfully rebased and updated detached HEAD.

  3. git log --oneline --graph

     * f647a1b Some Changes in EG proj * 536029f Redact Task * 44cc081 Add xmlResult * 370584a EGp with MetaCode * 96c5388 Add EG progect to test * 765ca4c v5HDFS * 5da3f2a v4HDFS * cedc686 v3HDFS * 28d0e1a v2HDFS * a6f9d63 v1HDFS * e5f373a v3 * 708e3b6 v2 * c89f76a First commit 
  4. git checkout master

     Warning: you are leaving 1 commit behind, not connected to any of your branches: f647a1b Some Changes in EG proj If you want to keep it by creating a new branch, this may be a good time to do so with: git branch <new-branch-name> f647a1b Switched to branch 'master' Your branch is up-to-date with 'origin/master'. 
  5. git log --oneline --graph

     * c9ec96c Some Changes in EG proj * 928b5ea Merge branch 'testHDFS' |\ | * 1504e3f Redact Task | * a9dffca Add xmlResult | * 82cd8fb EGp with MetaCode | * db93620 Add EG progect to test * | 536029f Redact Task * | 44cc081 Add xmlResult * | 370584a EGp with MetaCode * | 96c5388 Add EG progect to test |/ * 765ca4c v5HDFS * 5da3f2a v4HDFS * cedc686 v3HDFS * 28d0e1a v2HDFS * a6f9d63 v1HDFS 

I understand that a new branch has been created and I can switch to hash by head. But I do not understand why the old commits did not go away. I tried to drop them through rebase and reset. If you enter the rebase command for f647a1b (recalculated commit) , then it is looked at commits that are "above" c9ec96c . Apparently, the relocation did not happen to the end and a conflict appeared.

  • 1. It’s hard to say why you had errors in step 4, but you can reset master pointer to any commit you can by using the reset command with the --hard option: $ git checkout master && git reset --hard f647a1b . 2. “orphaned” commits will be deleted only after “garbage collection”. 3. since you rewrote history, to rewrite it in the “outside world”, the push command will have to be done with the -f option. and I hope you know that rewriting the history in the repository, which is used by more than one committer, can make all your manipulations meaningless. - aleksandr barakin
  • @alexanderbarakin? thanks again big. Understood more or less with the process. It helped me that I removed information about the unnecessary branch in commits 765ca4c and 536029f . The problem really was that I switched from the relocation process to which branch. In order to avoid the "reset" relocation, you constantly had to call git branch and git status . After the resolution of all conflicts. everything went well. Thanks again. - Sanek Zhitnik

1 answer 1

as far as I understand, you want to delete four “duplicated” commit (and merge commit).

For this, you can use the interactive option of the rebase command :

 $ git rebase -i коммит.до.разветвления 

example:

 $ git log --oneline --graph * aabf478 7 * 5430d97 6 * 696565e bind |\ | * dff29c3 15 | * 5709144 14 | * 133cf40 13 * | 1807d0e 5 * | f61ce99 4 * | c5c42a9 3 |/ * c521dd2 2 * fd32efc 1 

it is required that the story look like this: 1 - 2 - 3 - 4 - 5 - 6 - 7 , and commits with messages 13 , 14 , 15 and bind - generally remove.

in this case, a commit to fork is a commit with message 2 and hash c521dd2 :

 $ git rebase -i c521dd2 

The editor will open with the following lines (note that there is no merge commit with the bind message in this list (and should not be)):

 pick c5c42a9 3 pick f61ce99 4 pick 1807d0e 5 pick 133cf40 13 pick 5709144 14 pick dff29c3 15 pick 5430d97 6 pick aabf478 7 

you just need to delete the lines with messages 13 , 14 , 15 , so that the following list remains:

 pick c5c42a9 3 pick f61ce99 4 pick 1807d0e 5 pick 5430d97 6 pick aabf478 7 

save the file and close the editor. git will finish the job and issue something like the following:

 Successfully rebased and updated refs/heads/master. 

Now the story looks as required:

 $ git log --oneline --graph * 894f56f 7 * 305ff84 6 * 1807d0e 5 * f61ce99 4 * c5c42a9 3 * c521dd2 2 * fd32efc 1 

naturally, the hashes of overwritten commits (with messages 6 and 7 ) have changed. but their “content” remains the same, and the working directory now has the same “picture” as before the call to rebase .

  • @alexander_barankin, thanks for your reply. Completed the question. - Sanek Zhitnik