5

Background

I just noticed that the entire commit history in my repo is doubled up.

For reference, I am the sole contributor, and it's a private repository.

It will appear as if there are two contributors, because I have an old account, whose info was still in git config --global user.email on one of my computers.

The doubling-up occurred after I cloned the project and started working on it from another computer.

Excerpt from git log:

commit 76cd0efa307e501abfe13cd907957e4dcff7e75e
Author: myaccount <account1@gmail.com>
Date:   Mon Mar 21 18:58:39 2016 +0100

FEATURE - Add VideoNotFoundException.

commit 0430ef9dc5d3baa2189ba1c18b4bedb9d2940e51
Author: myaccount <account2@gmail.com>
Date:   Mon Mar 21 18:58:39 2016 +0100

FEATURE - Add VideoNotFoundException.

commit 94e7221e472e29119c9e4fe48944cd4d7528e207
Author: myaccount <account1@gmail.com>
Date:   Mon Mar 21 18:41:11 2016 +0100

FEATURE - Add previous/next video links to video view.

commit 8b26a51b84d4fb3ae72eefe2834649ff8bc8b7ce
Author: myaccount <account2@gmail.com>
Date:   Mon Mar 21 18:41:11 2016 +0100

FEATURE - Add previous/next video links to video view.

commit 7f9b3b6f214e445918d509d7f9377d3d7ce875da
Author: myaccount <account1@gmail.com>
Date:   Tue Mar 15 17:05:46 2016 +0100

CLEANUP - Remove unused code/uses.

commit c83fa2c238d1437c967b40d6e807c2567eb7572d
Author: myaccount <account2@gmail.com>
Date:   Tue Mar 15 17:05:46 2016 +0100

CLEANUP - Remove unused code/uses.

There are now 234 commits in the repository, of which about half are actual, real commits.

This is also reflected on GitHub:

enter image description here

git log --graph --decorate --oneline --all however does NOT reflect this.

*   303bbfe (HEAD, origin/master, origin/HEAD, master) MERGE
|\  
| * b8052ce REFACTOR - Refactor front page content for maintainability.
| * b5907b2 VISUAL - Improve front page mobile view.
| * 0430ef9 FEATURE - Add VideoNotFoundException.
| * 8b26a51 FEATURE - Add previous/next video links to video view.
| * c83fa2c CLEANUP - Remove unused code/uses.
| * 9e82b8f BUGFIX - Fix redirecting /login to front page.
| * 491b88e BUGFIX - Redirecting old playlist and video links to new ones. WIP: Code duplication!
| *   a7da158 Merge branch 'master' of https://github.com/alrasch/UDLv2
| |\  
| | * a3bfe1b BUGFIX - Fix 500 error on 404 page.
| * | 258d2e9 BUGFIX - Redirecting old URLs to new ones.
| |/  
| * 4426681 FEATURE - Add more UDL logo assets.
| * 7d15c7c FEATURE - Add custom 404 page.
| * 6fbb5dd FEATURE - Add 'forgot password' function.
| * 92dd4c8 VISUAL - Fix video view layout.
| * 8a7decb VISUAL - Scale UDL logo to 75% on front page.
| * 0900fbc VISUAL - Rearrange discipline view layout.
| * 1ba38c8 VISUAL - Scale UDL logo on playlist view down to 75%.
| * eef7cd1 VISUAL - Fix playlist view layout.
| * b7fa6cb Made sidebar space on front page.
| * ace9fb6 COSMETIC - Logo on front page and navbar. Rounder buttons.
| * bbf12b3 Add MathJax LaTeX sitewide.
| * 6629128 Customize register form and add email activation.
| * 27f7114 FEATURE - Add basic search to navbar.

My attempts

I'm not opposed to rebasing and squashing if that's what I have to do. I've tried using git rebase -i HEAD~n but the doubling-up is not reflected in the list of commits there, so I can't.

Question

Can I reset the repository to an earlier state (based on a point in time)? (For reference, my repo is on GitHub.)

If nothing works, I suppose I could start the repository anew, as all functionality is preserved. It's just a messy history.

Related question

Please do not close as duplicate of Fixing git double-commit history. While the questions are similar, the accepted answer doesn't apply to my case, as the doubled commits are not reflected in the git rebase file where you choose pick/squash.

Community
  • 1
  • 1
Alec
  • 1,986
  • 4
  • 23
  • 47
  • 1
    Are you supplying any additional arguments to `git log`? Also, try `git log --graph`, or `git log --oneline --decorate --graph` (adding `--graph` is often quite revealing); and also look at `git log --oneline --decorate --graph --all`. – torek Mar 31 '16 at 20:22
  • Is this reflected in the history on Github? – Oliver Charlesworth Mar 31 '16 at 20:23
  • @torek - `git log --graph` shows all doubled commits on the same "line" so to speak. There's no divergence. The only parts where there is divergence, is when I merged other branches into master. There are doubled commits there too. – Alec Mar 31 '16 at 20:24
  • @OliverCharlesworth - Yes, GitHub shows the doubling too. – Alec Mar 31 '16 at 20:24
  • http://stackoverflow.com/questions/22817360/fixing-git-double-commit-history – Oliver Charlesworth Mar 31 '16 at 20:26
  • @OliverCharlesworth - Yes, I read that. My question differs in that I cannot rebase as the list of commits in the rebase doesn't show doubling commits. Or... I guess the question is the same, but the accepted answer doesn't apply, and there are no other answers. – Alec Mar 31 '16 at 20:27
  • I'd definitely need more information to figure out what did happen and/or what to do about it. The `git log --graph --decorate --oneline --all` output, for instance, might help, or (much shorter and simpler) a link to the github repo. – torek Mar 31 '16 at 21:13
  • @torek - It's a private repo, but I can give you access. I'd really appreciate the help. What is your user? – Alec Mar 31 '16 at 21:29
  • @torek - `git log --graph --decorate --oneline --all` actually did NOT reflect the problem. Added output to question. – Alec Mar 31 '16 at 21:38
  • This is actually pretty interesting. I'd go as far as opening an issue with Git suspecting it's a bug. (Worst case, Linus tells you to f off) – Madara's Ghost Mar 31 '16 at 21:43
  • 1
    I'd LOVE to be on the receiving end of a Linus email! – Alec Mar 31 '16 at 21:55
  • Hmm, very interesting ... if `--all` does not show the duplicated commits, what reference is bringing them in? Without `--all`, `git log` should be using `HEAD`, but `HEAD` points to `303bbfe` (perhaps through `master`, if your git is a bit older and does not have the new `HEAD -> ...` notation) which doesn't lead to the duplicated commits Usually this sort of duplication results from using `git filter-branch`, which does in fact copy commits, and accidentally leaving the old commits in as well. Did you use `filter-branch`? Are there some tags, perhaps... – torek Mar 31 '16 at 23:20
  • @torek - Yes, I have indeed used `git filter-branch`. I used it to try and change the author of all my old user's commits to my new one. I used it as described in this guide: https://help.github.com/articles/changing-author-info/ – Alec Apr 01 '16 at 07:59
  • OK, the recipe on github looks correct (has a tag name filter). So some reference(s) still get you to the old commits, before filter-branch copied them to corrected ones. The trick is to figure out what those references are. The repo used for filtering keeps them in `refs/original/refs/*` so make sure you don't have any of those copied to github and/or your local repo... – torek Apr 01 '16 at 18:05
  • I've contacted GitHub staff, who are looking into it, so I'm afraid to start tinkering for myself. I might just get in the way. I'll make an answer-post if they resolve and explain it. Alternatively, they might do it themselves, as they are aware of this question. – Alec Apr 02 '16 at 12:40

1 Answers1

1

This answer is what was recommended by the GitHub team over e-mail, after about a week of investigation.

Cause

At some point, I did a git filter-branch, after which I force-pushed (git push -f origin), but I neglected to rebase my local clone. On the next push, my local history was pushed on top of the remote history, causing the doubling-up of commits.

Solution

Sadly, there is no quick fix for this. The solution, as was my initial suspicion, was that there needs to be a complete rebase of all commits, whereby you pick and squash each pair of double-commits.

For this, you can use Git's interactive rebase tool.

For repositories with any substantial history, this is going to be quite the task, and could be very time-consuming.

Alternate solution

The working tree is still in good shape, so another solution is to simply migrate the working tree to a new project.

Caution: You will lose your commit history by doing this, but let's face it, that's the goal in the first place.

Alec
  • 1,986
  • 4
  • 23
  • 47