-1

Sometimes a piece of work (let's say a file) is not necessary anymore. For example, a perl script that was used to perform a certain action is not used anymore because the action is deemed useless now.

I don't like keeping useless stuff around so I usually delete the file, knowing that I can always get it back later from my repository history.

But sometimes, looking ahead, it's possible to guess that the now unnecessary feature will be needed again at some point in the future. And when that happens I won't be happy to go fish all the discarded files in my repository history.

What do you recommend for cases like this?

DylanM
  • 333
  • 2
  • 5
  • 17
  • 1
    I recommend you do nothing. Keep the script in the repo, and don't use it. – William Pursell Mar 05 '21 at 14:36
  • 2
    I delete files that I don’t need. They’re always retrievable so they’re not gone. You could even tag the commit before if you need an easy reference – evolutionxbox Mar 05 '21 at 14:41
  • I think you're asking the wrong question. If you knew that it is really easy to find all deleted files in your history and filter them by name or path for the one you want, you probably wouldn't think twice about deleting them. This question and answers should solve that for you: https://stackoverflow.com/q/7203515/184546 – TTT Mar 05 '21 at 15:03

3 Answers3

1

Personally, I think there's nothing wrong with an archived/legacy folder. That way you can still find it easily.

Alternatively you can have a section in your README.md and provide the commit to the last version of the code (though that would require remembering to keep it updated).

astrochun
  • 1,642
  • 2
  • 7
  • 18
1

As long as you include the filename in your commit message, you could do:

for i in $(git rev-parse :/"filename.txt"); do git show "$i"; done

This would show all commits with messages related to your file's name. Then, you can just revert the corresponding commit by id.

The more specific you are in your commit message, the better, such as delete filename.txt so that you could just do:

for i in $(git rev-parse :/"delete filename.txt"); do git show "$i"; done
Nick Mancuso
  • 171
  • 6
1

I won't be happy to go fish all the discarded files in my repository history.

Why?

git log --oneline --name-status --diff-filter=D -- your/script

to list all deletions of your/script, or

git show `git log -1 --diff-filter=D --pretty=%h~:your/script -- your/script`

to see the latest, change show to checkout to get it back directly.

jthill
  • 55,082
  • 5
  • 77
  • 137