Question

I use git for versioning. Just yesterday I was working on refactoring my Python code base. After adding a test I found that I had introduced a bug in one of project euler solutions. So I checked out a previous version offline, found the diff and went back to latest version and fixed the problem.

It was a bit after that I found a mess up had been done due to this. I use .gitignore to leave many of the unneeded files or WIP things out of git. I found that using checkout and going back to the latest version deleted some files which were not checked in. Now I am finding that a new repo that I keep in an ignored Folder is completed cleaned. It did not have much so far but still all is gone.

So I am confused about what is a good way to keep offline codebase intact in case there are many such folders/files that I do not want to check in? Also how to organize codebase on local for new projects? Just take backups on a drive?

Was it helpful?

Solution

git does warn you if it is going to modify or delete untracked or uncommitted files. Don't take this lightly.

Do check in everything you work on, all WIP stuff, all temporary stuff. If you can't carelessly delete a file outright, track it. Make a lot of small commits. Once something started to work, commit it; don't mind that it's yet imperfect.

If you care about cleanliness, use separate branches: keep 'master' clean and wildly experiment on feature branches. Branching is incredibly cheap in git. When you want to pull a feature in, use merge or cherry-pick.

If amidst a change you need to check out another commit, git stash is your friend. You can git stash pop on the same or on a different branch; great when you just realized that you had started working on a wrong branch.

And again, look at all your untracked files as useless trash that a janitor may choose to take out at any moment. If something is not trash, git add it.

Licensed under: CC-BY-SA with attribution
scroll top