I've just written myScript.sh
, which fixes something specific at this point in time in my project and will do nothing after being executed once.
Since all our code is tracked in Git, and to share it with colleagues, I want to commit it : it's important for us to know what piece of code was run and when it was run. But since it's a single-use script, I also prefer to remove it so that it won't clutter our workspaces.
So I'll have 2 successive commits :
commit1 : ADD myScript.sh to do foo bar
commit2 : DELETE myScript.sh which did its job and is not necessary anymore
Will myScript.sh
stay as-is in Git history (invisible in the working area but still available for a future checkout, which is fine to me) or are there any "housekeeping" functionalities of Git that will detect the successive add + remove commits and just discard both ?
Yes, the script will stay in git's history indefinitely.
While git does have some "housekeeping" functionalities that delete things after a while, this only applies to things that are meant to be temporary, for example dangling commits (commits that are not reachable from any branch, e.g. after use of git rebase
) or the reflog.
The main history is never cleaned or changed automatically - that is one of the central promises of git.