Removing Git History as a result of adding the wrong remote repo

Seek a bit of Git help if possible. I am new to Git and try to learn so bear with me;)

In short, I have two remote repositories configured on two different servers. I had one setup, but when adding a second, I accidentally added a repo from an existing project.

Then I pulled out of this second wrong repo and got all the commits made. I deleted this wrong remote repo, but commits still exist in the tree: -S There are all my real commits at the top, then a break, then all are wrong.

Anyway, can I remove all of these commits from my commit history, since I would like to keep my tree as clean as possible?

Any help would be appreciated in this regard.

Thank you in advance

+4
source share
4 answers

Can git reset --hard make an error before being pressed incorrectly? If hash1 was commit before the "break", you can do git reset --hard hash1

If at the top you understand that your commits are after these incorrect commits or if these commits are scattered throughout your history, I would suggest git rebase -i and remove the commits from being pressed incorrectly.

+1
source

As I understand it, you need to do something like this:

 git rebase -i HEAD~5 

A text editor will appear showing the last five commits. Just remove the ones you do not want from the list and save. git will update the index by removing commits you don't want.

0
source

First, remove any local branches that you might have checked from the wrong remote with git branch -d branchname (possibly with -D if it complains that it doesn't merge with master, but use this with caution).

Then, after deleting the remote, you need to remove the remote branches from your repo using git fetch --prune .

Finally, you can use git gc to remove the remaining lost references to orphaned objects.

0
source

You just follow

 git gc 

after removing the remote.

If you have local links pointing to the wrong branches, delete them first.

Also, note that links are stored for security in magazines and as dangling ones. They usually expire in time, but if you want, you can speed it up:

 git gc --aggressive --prune=tomorrow 

Do this only if you are sure that you will not need to restore something that you accidentally deleted.

-1
source

All Articles