Home > Software design >  How do I ask git to clean out and rebuild the entire working tree?
How do I ask git to clean out and rebuild the entire working tree?

Time:02-04

We have something of an ugly mess that needs cleaning up.

In our codebase, certain developers created directories whose name differed only in case. Normally, such a thing would not be an issue; however we are developing on Windows. This proceeded to confuse git and cause us merge conflicts far down the line.

We have since pushed changes to master getting rid of the duplicate directories in the tree (and encountering some Azure DevOps bugs in the process); now all that remains is a large number of incorrect directory names on users' workstations. Due to the case interactions between git and Windows; these won't get cleaned up by a git pull.

How do we actually erase and rebuild the working trees without throwing out the local branch state in .git? I need to send out instructions so everybody on the team can clean this mess up and those wrong-case local directories don't magically reappear in future commits.

CodePudding user response:

Delete all files and then do a git reset --hard.

git rm -r .
# might need an additional rm outside of git if there are directories left over there
# wait 30 seconds or Windows will restore the wrong case
git reset --hard

Just be careful not to have any uncommitted changes hanging around.

  • Related