0

Here is the scenario:

  1. On a smallish Ubuntu web server I have a git server running. The website is checked out from git repository. I had a bulk of changes that I added and committed. Git diff showed 50+ code files updated and 20000+ image files. I did not paid much attention to this thinking these should be ignored, my fault. A bit stupid but I thought it was quickest to just commit all changes as a bulk. Let's call it commit A

# Commit A git add . git commit -m "Changes so far in this year"

  1. I discovered that I forgot to exclude working/output files (huge number of generated images). Other than these files (around 20000) I had about 50+ files with code changes.

  2. After reading online and git manual I understood that best bet was to update .gitignore and generate a list of files to remove and remove cached. This should remove from commit but not the local folder. Let this be commit B

# Commit B vi .gitignore git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached git add . git commit -m "Cleanup of generated files from commit history"

  1. Trouble is that now my git push fails with following error

git push origin master Counting objects: 19219, done. error: pack-objects died of signal 9 error: pack-objects died with strange error error: child process died of signal 9 error: died of signal 9 error: failed to push some refs to '/srv/gitrepositories/xxxx.git'

Answers on this question about error 9 suggests it might be due to git running out of memory.

My options?

  • Is commit A & commit B made up of huge number of objects, which looking at the count above it seems?
  • Is there a better way to clean this mess up with possible option to remove commit A & commit B altogether from history and get my changes intact?
  • Idealy I want to go back to stage where my git diff reports only the 50+ code files. Images are now ignored by .gitignore
  • Can I delete a git commit but keep the changes? Is this what it sounds like? Can I do it twice for both commit A and commit B?
Community
  • 1
  • 1

1 Answers1

1

Yes, you can use git reset HEAD~2 to clear the last 2 commit from history permanently while keeping the changes in the working directory, then git push -f to force push your changed history to the remote.

If your repo is shared with others it's not advisable to change your commit history.

Roy Wang
  • 11,112
  • 2
  • 21
  • 42
  • Thanks, the repo is not shared. The commits are not pushed yet. Would `git reset HEAD~2` mean that we will only be left with uncommitted changes and no commit history for A & B? – Stack Overflower Feb 11 '16 at 12:52
  • Yes. It will be like the same state as right before you made the 2 commits. Changes will be kept in working directory. – Roy Wang Feb 11 '16 at 13:03