How to say 'git' to "forget" ALL previous commits?

I need to start a new project based on one tiny piece of another of my project whose repo is on github.

I made a git clone in a new project folder ... excellent.

I deleted everything that I do not need, got rid of old migrations, etc. .... excellent.

now it works fine locally, BUT 'git log' shows ALL old commits.

I want to say git "forget ALL previous commits, this is a new project, so forget everything so far, start right NOW as the first commit"

I read about git rebase, but it is not clear if this is the right command, and if so, how to use it for this very simple purpose.

+6
git
source share
4 answers

Delete the .git folder, run git init and git add

+12
source share

The answer accepted here really scares me - deleting your .git directory is a very important thing and it is not necessary here.

This script takes a safer approach - it creates a branch called old-master to record where you were before starting to crush commits, and then uses git reset --soft $ROOT_COMMIT and git commit --amend to crush the entire branch to single commit, you can also load the script from this github gist .

 #!/bin/bash # A script that squashes your entire current branch down to a single commit, # if this repository has a single root commit. This will change the object # name of the root commit. if [ -n "$(git status --porcelain)" ] then echo "git status wasn't clean - refusing to run..." exit 1 fi # From: http://stackoverflow.com/questions/1006775/ root_commits () { git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$" } NUMBER_OF_ROOT_COMMITS=$(root_commits|wc -l) if (( "$NUMBER_OF_ROOT_COMMITS" > 1 )) then echo "This script won't work when you have multiple root commits" exit 1 fi ROOT_COMMIT=$(root_commits) if [ -z "$ROOT_COMMIT" ] then echo "No root commit was found!" exit 1 fi set -e set -x # Create a branch based on the current HEAD for safety: git branch old-master # Reset the branch to the root commit, leaving the previous # state of the tree staged: git reset --soft $ROOT_COMMIT # Now amend the root commit with the state of the index: git commit --amend -m "The branch restarted" 
+9
source share

Have you tried reposurgeon ?

http://www.catb.org/~esr/reposurgeon/

0
source share

Why not just copy this directory to the new git repository and commit it there?

0
source share

All Articles