Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Sign in
O
OHR Support
  • Project
    • Project
    • Details
    • Activity
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 97
    • Issues 97
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • Wiki
    • Wiki
  • image/svg+xml
    Discourse
    • Discourse
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Commits
  • Issue Boards
  • Projects
  • OHR Support
  • Wiki
  • Project re structure tips

Project re structure tips

Last edited by Projects May 20, 2014
Page history

Tips to re-structure a project and clean up a git repository

  1. Create a backup of the project.
  2. Move binary files out of the repository (e.g. to the "Files" or "Documents" section).
  3. Remove binary and big files from git history, see below.
  4. Split the repository into new ones (hw, gw, tst and sw).
  5. Set sub-modules up in the new repositories (if any).
  6. Re-organise the folders (if needed) and update hard-coded paths.

Removing big file from git history

1. List big files

git rev-list --objects --all | sort -k 2 > allfileshas.txt

git gc && git verify-pack -v .git/objects/pack/pack-*.idx | egrep "^\w+ blob\W+[0-9]+ [0-9]+ [0-9]+$" | sort -k 3 -n -r > bigobjects.txt

for SHA in `cut -f 1 -d\  < bigobjects.txt`; do
echo $(grep $SHA bigobjects.txt) $(grep $SHA allfileshas.txt) | awk '{print $1,$3,$7}' >> bigtosmall.txt
done;

2. Remove file from git history

WARNING, this will change the SHA of the commits where the deleted file was referenced!!*

git filter-branch -f --prune-empty --index-filter 'git rm -rf --cached --ignore-unmatch MY-BIG-DIRECTORY-OR-FILE' --tag-name-filter cat -- --all

3. Final clean-up

rm -rf .git/refs/original/ && git reflog expire --all --expire-unreachable=0 && git gc --aggressive --prune && git repack -A -d && git prune

4. Check the result

du -sh

Sources

  • http://naleid.com/blog/2012/01/17/finding-and-purging-big-files-from-git-history/
  • http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/
  • http://www.ducea.com/2012/02/07/howto-completely-remove-a-file-from-git-history/
Clone repository
  • Administrator guide
  • Documents
  • Folder structure example
  • Gitlab migration of ohwr faq
  • Home
  • Local git backups
  • News
  • Project structure guidelines
  • Project guidelines
  • Project re structure tips
  • Project review by ht volunteers
  • Repository use
  • Repository use2
  • Documents
    • Ohr logos
    • Ohwr new design visuals
More Pages

New Wiki Page

Tip: You can specify the full path for the new file. We will automatically create any missing directories.