0
  • TL;DR- How can I make my previous commits invisible on a repository which was once private and is now public?

So, I was one day working on a project which was on my private repo, after when I was done I made it public but my commits are visible to others and some threating information is also being leaked. So I had to make it private again. Please help me out to sort it, I'm still learning.

Tried Googling but results we irravenat and steps were too complicated.

NERFELITEWAR
  • 9
  • 1
  • 4

2 Answers2

-2

You'll need to rewrite your branch history, which may break a lot of things.

To rewrite history, use rebase:

git rebase -i <commit-hash-with-the-oopsie>~1

Then:

  1. Replace "pick" with "edit" on the first line of the opened git-rebase-todo file
  2. Save-exit git-rebase-todo
  3. Change or delete the file with the oopsie
  4. git add the file with the oopsie
  5. Run git rebase --continue and wait for it to finish.

When it finishes, you'll have a differing branch history that doesn't commit an oopsie.

Caveats (there are many)

  1. Having more than one branch complicates things, and any related branches with the old oopsie commit will also need to be reconstructed. Find them using the following command:
git branch --contains <commit-hash-with-the-oopsie>

Same goes with tags:

git tag --contains <commit-hash-with-the-oopsie>
  1. If your branch contains merges, they'll effectively be flattened into a linear git history, and any conflict resolutions will need to be re-done. There is a way to preserve merges during rebase, but I've not gotten it to work very well.

  2. Your name will be the committer on all the commits after <commit-hash-with-the-oopsie>. The commit date will also change.

  3. The commit can persist in .pack files inside the git objects directory until anything that references it is more than 2 weeks old and you run git gc. You can force git's hand in this using git reflog expire --stale-fix --expire-unreachable=now --all --rewrite && git gc --aggressive && git prune

amphetamachine
  • 27,620
  • 12
  • 60
  • 72
-2

If you're trying to edit your last commit, then git commit --amend might be useful. For older or multiple commits you can use git --rebase. Check out this link: https://www.atlassian.com/git/tutorials/rewriting-history for information on using those commands. What I ended up doing, in a similar case, was deleting the whole repo and rebuild from the start. :P