0

What is the git command to keep the history file size to a minimum?

Scenario is, due to platform issue, I need to commit the WAR file for my Java web app every time it gets built and re-built. I can easily "add" it to git when during the build process it got deleted and recreated causing it to be a different file even the same file name.

Now what I want to be able to do is to keep the history size to a minimum, my WAR size is about 60MB and is growing a bit each time. I don't want to have a new version of that 60MB file for each commit I will do.

What should be done to achieve this?

quarks
  • 33,478
  • 73
  • 290
  • 513
  • Does that mean you don't want to keep old versions of the file? – Sascha Wolf Dec 18 '14 at 18:51
  • Yes for that specific file. Also since the git repo is dedicated for deployement and not code history, git history might not be needed. The case is its Openshift, and to deploy and app, it usually needs to be through 'git push' – quarks Dec 18 '14 at 18:56
  • 1
    Look at the answers on http://stackoverflow.com/questions/540535/managing-large-binary-files-with-git. It discusses something called git-annex (which is new to me). Don' t just look at the accepted answer – kdopen Dec 18 '14 at 19:03
  • Is it like you want to delete the existing war(from history) and commit a new war file every time there is a change? – pratZ Dec 18 '14 at 19:09

1 Answers1

0

If you do not want to keep the history for the war file, you can delete the war file completely from the history.

git filter-branch --tree-filter 'if [ -f <old-war-file> ]
then
   rm <old-war-file>
fi' --force HEAD

You can then commit the new war file, which will not have any history associated with it.

git add <my-new-war-file>
git commit -m <commit-msg>

Here's another way to remove the file from history.

You need to do it every time you commit a new war file.

Community
  • 1
  • 1
pratZ
  • 3,078
  • 2
  • 20
  • 29