Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good way to manage cleanup commits in git for a legacy project?

I have a large codebase, where almost every single file isn't aligned properly, has bad spacing between variables or methods, or just generally ugly code.

I'd like to make it better as I work with it, but fixing things like indentation makes the commit history pretty ugly.

I'm not talking about small indentation issues where a line is one space off, I'm talking about something like

 class Xyz
def foo
end

   def bar
  @something
end
   end

What's a good way to clean up code like this, while keeping my history relevant? Should I just auto-align everything at once and do one huge commit?

like image 258
Jakub Arnold Avatar asked Jan 02 '12 09:01

Jakub Arnold


People also ask

How do I clean up commit history?

Steps to get to a clean commit history:understand rebase and replace pulling remote changes with rebase to remove merge commits on your working branch. use fast-forward or squash merging option when adding your changes to the target branch. use atomic commits — learn how to amend, squash or restructure your commits.

What command will get you back to a clean commit point with a synchronized working tree?

git stash. git stash allows you to get back to a clean commit point with a synchronized working tree, and avoid losing your local changes in the process of switching branches or tasks.


2 Answers

I would fix all this in a separate (local) branch. Once I'm ready I would make a "squash merge"

git checkout -b cleanup develop
# Do some cleanup, do some commits and so on
git checkout develop
git merge --squash cleanup 
git commit -m "My Cleanup"
git branch -D cleanup

This way I would get a "huge commit" with this changes, but I would not trust any auto-formatter (at least not completely) and I have not to do it on one day, or completely without any commit until merging.

like image 149
KingCrunch Avatar answered Oct 14 '22 05:10

KingCrunch


You could do the clean up in a separate branch and when done merge it back into the main branch.

This gives you time to clean up and you do not have to edit history (something I never do)

like image 42
Emond Avatar answered Oct 14 '22 05:10

Emond