I’m having some issues with duplication of some commits in my repository for a project. Unfortunately, the errors that I must have made to bring about this duplication happened four months ago, so my memory on what I did to bring this about is pretty hazy.
The project can be found here: https://github.com/benvessely/brevets. This all started because I realized that I had accidentally been tracking a confidential file, credentials.ini, in my repository for a while, and the file had subsequently been pushed to Github. I wanted to get rid of this file from my commit history, so I used git filter-repo, which I think worked correctly. I sort of remember doing something involving a pull and a rebase here, though again I can’t remember exactly. Sorry I can’t be of more help with that.
This pushing/pulling occurred just after the commit with hash starting with a72b0. I then made a few more commits, and then did some sort of merge at the most recent commit. Unfortunately, I really can’t remember why I did this merge either, and git show
didn’t tell me anything. After this point, I stopped working on the project for 4 months, apparently without noticing the duplication in my repository.
Where I’m at now is that between commits with hashes 4aa07 and a3dee, not inclusive, I believe there are two branches with duplicated commits, one which contains the credentials.ini file and one that doesn’t. The commits do have different hashes, but they contain the same message and the same files, with credentials.ini being the only difference. For all commits up to 4aa07 (before the duplication) and past a3dee (after the duplication), the commits also all don’t have the credentials.ini file. It’s just that section in the middle that is duplicated and still contains the bad file.
One thing to note is that when I use git log –graph, it shows some weird deviations of the graph that do make me think that the merge was maybe part of the issue. My grasp on all these concepts is still not totally solid, but it kind of looks like the problematic branch was coming from the remote, which was then merged into what was my local branch.
Basically, I'm wondering how I can get rid of those duplicate commits that contain the confidential file? I know that this is potentially a tough question given the lack of detail I’m able to provide, but I would really appreciate it if anyone would be willing to take a look at this and let me know their ideas. Thanks in advance!
Your repository looks like this.
> git log --graph --decorate --oneline
* 74d2daf (HEAD -> master, origin/master, origin/HEAD) Merge branch 'master' of https://github.com/benvessely/proj6-rest-vessely
|\
| * a72b0d4 Submit now doesn't work if there are any notes (i.e. errors). Bug still exists with submitting without refocusing first
| * 7b4c763 Error messages go away after change of km/miles (though may return immediately)
| * a50d818 Submit button delays before submit to give time for AJAX; other little adjustments
| * dbd4f79 Return button now works as desired with starting options too
| * b76e770 Fix return key behavior in table; move JS from calc.html into calc.js
| * 15b7c2e Added to and revised README, though could still be reworked more
| * 5b2f24e Fixed bug for consumer program when database empty
| * 6d31a0d brevets_proj6 is now brevets
* | 2399188 Adjust time delay for submit
* | de2a148 Errors resizing table fixed by changing table spacing and error width
* | a3deeb2 Restoring state of files before performed filter-repo to remove credentials.ini from history
* | 368362d Submit now doesn't work if there are any notes (i.e. errors). Bug still exists with submitting without refocusing first
* | 688371b Error messages go away after change of km/miles (though may return immediately)
* | 981e001 Submit button delays before submit to give time for AJAX; other little adjustments
* | f8bf5a9 Return button now works as desired with starting options too
* | 5c3b741 Fix return key behavior in table; move JS from calc.html into calc.js
* | fad18bf Added to and revised README, though could still be reworked more
* | a18a83c Fixed bug for consumer program when database empty
* | 9227a27 brevets_proj6 is now brevets
|/
* 4aa0739 Delete data-samples and DockerRestAPI, renamed brevets_proj6 to brevets
* 45d26df Basic consumer program working
...
I'm going to guess that a72b0d4 is your history before filtering and 2399188 is your new history that you want to retain. I'm further going to guess that after filtering you tried to git push
and Git said your branches had "diverged" and you should git pull
to fix this. git pull origin master
is a git fetch origin
+ a git merge origin/master
, it fetched your old master from the remote and merged it with your new master "solving" the divergence problem.
Branches are just labels pointing at a commit. We can get rid of the duplicates by moving master to 2399188 just before the merge using git reset --hard
. Then we can safely move master on your remote with the confusingly named force push with lease.
> git reset --hard 2399188
> git log --graph --decorate --oneline
* 2399188 (HEAD -> master) Adjust time delay for submit
* de2a148 Errors resizing table fixed by changing table spacing and error width
* a3deeb2 Restoring state of files before performed filter-repo to remove credentials.ini from history
* 368362d Submit now doesn't work if there are any notes (i.e. errors). Bug still exists with submitting without refocusing first
* 688371b Error messages go away after change of km/miles (though may return immediately)
* 981e001 Submit button delays before submit to give time for AJAX; other little adjustments
* f8bf5a9 Return button now works as desired with starting options too
* 5c3b741 Fix return key behavior in table; move JS from calc.html into calc.js
* fad18bf Added to and revised README, though could still be reworked more
* a18a83c Fixed bug for consumer program when database empty
* 9227a27 brevets_proj6 is now brevets
* 4aa0739 Delete data-samples and DockerRestAPI, renamed brevets_proj6 to brevets
* 45d26df Basic consumer program working
...
> git push --force-with-lease