Home > OS >  How can i set a git repository to ignore all previous commits and start from a new initial commit?
How can i set a git repository to ignore all previous commits and start from a new initial commit?

Time:10-08

I am new to version control software so in an attempt to get familiar with git I decided to use it in my unreal project. I'm using LFS but my file size became too large for a free package and so I initially made another commit after reducing the file size (I've become aware that this is a common rookie error). Bottom line is I want to just start from scratch where I'm currently at so I don't lose any of the work I've done since this issue. How should I go about doing this? I've tried rebasing my commits and it didn't really work, I'm unsure as to why.

Do I just need to start from scratch with a new repository or are there other alternatives?

I feel there should be an inbuilt option on git to ignore all previous changes and just start tracking changes from the current state as surely issues like this must need overcoming regularly?

CodePudding user response:

The way to set yourself so that you start on a completely new branch with no history is:

git checkout --orphan new-branch
# this new branch has _no_ history
git commit -m "First revision"
# then you can move main to this new revision
git branch -f main
git checkout main

Then you can force-push this new branch into a repository of your preference. I have no experience with LSF so I don't know how that part plays out.

  • Related