https://github.com/mevdschee/git-undelete-all.sh
Bash script to undelete everything that is easy to undelete in a Git repository.
https://github.com/mevdschee/git-undelete-all.sh
bash git undelete
Last synced: 3 months ago
JSON representation
Bash script to undelete everything that is easy to undelete in a Git repository.
- Host: GitHub
- URL: https://github.com/mevdschee/git-undelete-all.sh
- Owner: mevdschee
- License: mit
- Created: 2019-08-13T09:09:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-13T23:37:33.000Z (over 6 years ago)
- Last Synced: 2025-10-10T01:34:27.541Z (3 months ago)
- Topics: bash, git, undelete
- Language: Shell
- Homepage:
- Size: 23.4 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# git-undelete-all.sh
Bash script to undelete everything that is easy to undelete in a Git repository.
$ bash git-undelete-all.sh -h
Usage git-undelete-all [OPTION...]
-h help: print this usage information
-s silent: do not print output
-v verbose: print every file recovered
This script can come in handy when evaluating the history of a repository.
### Usage
Copy the script into the repository that you want to undelete files in and run:
bash git-undelete-all.sh
It should output something like:
1 files restored in 0 seconds
If you run with "-v" the script will print the filename of each undeleted file on a separate line.
### How it works
It is automating the following process (where "undelete.sh" is a deleted file):
1) List the files that are deleted from the Github repository:
`git log --pretty=format: --name-only --diff-filter=D | sort -u`
2) Which gives you the filenames of the deleted files:
`undelete.sh`
3) Then get the hash of the commit in which the file is deleted:
`git rev-list -n 1 HEAD -- undelete.sh`
4) Which gives you the hash of the undeletion:
`ae85c23372a8a45b788ed857800b3b424b1c15f8`
5) Now you can checkout the version of the file before the deletion:
`git checkout ae85c23372a8a45b788ed857800b3b424b1c15f8^ -- undelete.sh`
And doing that for every file in the list that is retrieved in step 2.