'How to "time travel" git repository back in revisions?

Is it possible to completely revert git repository to previous X revision on bitbucket so that it doesn't keep any changes after that X revision and doesn't contain any source code change newer than X revision.

For example if there are 1,2,3,4,5 revisions in the repo and i want to revert to revision 3, so that it's the last revision and completely wipe out any trace of revisions 4 and 5 as if they never were made and can't be retrieved.



Solution 1:[1]

Yes, you can do this there many ways to do this:

1) you can specify the time like 10.minutes.ago, 1.hours.ago, 1.days.ago ...

Ex: if you want to go back 5 days ago on the master branch git reset --hard master@{5.days.ago}

2) if you know the commit hash then you can go back to it directly git reset --hard <commit_hash>

Thanks!

Solution 2:[2]

You can clone the repo locally, git reset --hard <commit 3>, then git push -f back up to the remote. You would need to do this for all branches.

You should also be very careful when using -f to push - make sure you're pushing to the right repo/branch.

This will rewrite history for the remote repo, so you should inform any other consumers of this repo that there will be conflicts.

Read more here: https://git-scm.com/docs/git-push#git-push---force

Solution 3:[3]

doesn't contain any source code change

completely wipe out any change ... and can't be retrieved

If you really need to delete data that has been uploaded to a third party (Github, Bitbucket) you must follow their instructions for deleting the data. Just because the data is no longer on the main branch (or any branch) doesn't mean it isn't accessible at the commit's SHA identifier.

https://confluence.atlassian.com/bitbucketserverkb/how-do-i-remove-sensitive-unwanted-content-that-was-pushed-to-my-bitbucket-server-instance-1019389998.html

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository

These involve using either the BFG Repo-Cleaner or git filter-repo to remove all instances from throughout the repository; I recommend following the instructions given carefully.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rahul mishra
Solution 2
Solution 3 David McKee