Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"Refreshing" a cloned repo using git

Context:

  • working on a large project with thousands of files
  • project is built using gradle — build process is not documented; several files are generated
    and spread across a number of directories
  • generated files shouldn’t be added to git
  • project has no clean task — once built, generated files must be removed manually

Is there a way to undo the state of the project after build using git? only a subset of the output files is of interest and the others can be ignored but, as it stands, these files are not easy to find.

Can the state after build be reverted to the clean state (after clone)?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

One solution would be to add the generated files to a separate branch and work on that. Once built, the project is too large to be pushed to the repo.

Is there another way?

Run:

git clean -d . -X -f 

where

  • -d . tells git to recur into all directories starting from root (that has the .git dir)
  • -X tells git to remove all ignored files
  • -f just delete everything and don’t prompt

>Solution :

What you’re looking for is git clean.

Cleans the working tree by recursively removing files that are not
under version control, starting from the current directory.

Don’t forget to look at the documentation to know what flags to use. There is even a dry-run to test before removing things you didn’t want to be removed.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading