0

I'd like to pull down an application, remove all git commit history and re-push it up so that the entire app is there and functional as it was before but with only one commit i.e. "Initial Commit".

I'm thinking of doing it this way:

git clone https://github.com/user/user-repo.git
cd user-repo
git reset --hard tags/v2.0

rm -rf .git/
git init
git add .
git commit -m 'first commit'

git remote add stash ssh://git@myserver:7999/myproject/user-repo.git
git push --force stash master

Albeit, I'm not sure if this is the best way to achieve the desired results.

Please help!

Thanks!

vee
  • 38,255
  • 7
  • 74
  • 78
user3399101
  • 1,477
  • 3
  • 14
  • 29

4 Answers4

0

The reset command tells Git to move the current "position" back to a certain commit (in this case, your first commit), and adding the --soft flag tells Git to keep all the files as they are at your latest commit:

git reset <first commit> --soft

You can then commit all those changes you have made, amending the previous (initial) commit (the changes you have made in subsequent commits should already be staged for you):

git commit --amend -m "Initial commit"
IQAndreas
  • 8,060
  • 8
  • 39
  • 74
-1

You could, without deleting the .git/ directory:

git rebase -i <sha hash of the very first commit>

Then you'll a list of all commits applied in the order from top-down. Change every pick to squash, and every commit will be squashed up into the previous one, which should leave you with only one commit.

Kache
  • 15,647
  • 12
  • 51
  • 79
  • Thanks Kache! So i.e. it would be git rebase -i d9fcfde2b26d9d3b7a6b89a0fe78ee05b0db20cf (initial commit). And this would squash all of my latter commits into the initial commit? – user3399101 May 19 '14 at 17:46
  • `Rebase` begins an operation which will reapply commits. If you don't do anything, it will just reapply all commits over again as normal, which you don't want. I'll edit my answer to be more clear. Anyway, it appears that this question has already been answered pretty clearly elsewhere - you should read that one for a more complete and definitive understanding of your options. – Kache May 19 '14 at 17:47
-1

You can create a new orphan branch (that is, one without parents) and set the master branch to that:

$ git checkout --orphan new-master
$ git commit
$ git checkout master
$ git reset --hard new-master
$ git branch -d new-master
mipadi
  • 398,885
  • 90
  • 523
  • 479
-1

What you are trying is the most definitive way to remove history - Remove the .git and create a whole new repo and force push. It should work.

You can also do this (more conservative) approach:

git checkout --orphan temp
git add -A
git commit
git branch -D master
git branch -m master
git push -f origin master

Create an orphan branch (no parent), add the current working copy files to it and commit. Delete master branch, and rename the orphan branch as master. Force push the new master.

manojlds
  • 290,304
  • 63
  • 469
  • 417