Skip to content

Instantly share code, notes, and snippets.

@bonyiii
Created June 7, 2012 12:59
Show Gist options
  • Save bonyiii/2888682 to your computer and use it in GitHub Desktop.
Save bonyiii/2888682 to your computer and use it in GitHub Desktop.
Git restore accidentally deleted files
# Az alap koncepció innen származik: http://stackoverflow.com/questions/953481/restore-a-deleted-file-in-a-git-repo
# Csak a törölt fájlokat akarom visszaállítani a módosítottakat nem (ezt a grep 'D' és cut kombináció biztosítja)
# Elméleti:
git co $(git rev-list -n 1 HEAD -- <file_path>)~1 -- $(git diff --name-status $(git rev-list -n 1 HEAD -- <file_path>)~1 head | grep '^D' | cut -f 2)
# Egysorban az egész db könyvtáron mint példa:
git co $(git rev-list -n 1 HEAD -- db)~1 -- $(git diff --name-status $(git rev-list -n 1 HEAD -- db)~1 head | grep '^D' | cut -f 2)
# ugyanazon a branch -en maradunk mint voltunk és megjelennek az törölt file -ok. Ezután csak egy commit kell
pl:
# new file: db/migrate/20120216143016_create_teszts.rb
# new file: db/seeds.rb
################################
# Find the last commit that do with that file/directory.
git rev-list -n 1 HEAD -- <file_path>
# pl: 324dsdf3
# Amit visszaad az elé állunk eggyel.
# pl: 324dsdf3~1
# Lelistázzuk csak a törölt file -okat
git diff --name-status ae4958f head | grep '^D' | cut -f 2
# Majd csinálunk belőle branch -at
git branch new_branch_name 2e92835990a703451ae9a9600207ed61b0163c63
### Teszt
git diff --name-status $(git rev-list -n 1 HEAD -- <file_path>)~1 head | grep '^D' | cut -f 2
git co 515ed466d54c30f52690b09862d8aaa194d91770 -- $(git diff --name-status ae4958f head | grep '^D' | cut -f 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment