Obnova a vracení souborů

Introduction to Git

George Boorman

Curriculum Manager, DataCamp

Vznik chyby

Čtyři soubory v repozitáři, z nichž tři jsou přidány do oblasti staging a jeden je commitnutý: report.md, mental health survey.csv a summary statistics.csv

Introduction to Git

Vracení souborů

  • Obnova repozitáře do stavu před předchozím commitem

  • git revert

    • Obnoví předchozí verze a vytvoří commit
    • Obnoví všechny soubory aktualizované v daném commitu
    • a845edcb, ebe93178 atd.
    • HEAD, HEAD~1 atd.
git revert HEAD
Introduction to Git

Vracení souborů

git revert HEAD

Textový editor zobrazující, že commit

  • Uložení: Ctrl + O, poté Enter
  • Ukončení: Ctrl + X
Introduction to Git

Vracení souborů

[main 7d11f79] Revert "Adding fresh data for the survey."
 Date: Tue Jul 30 14:17:56 2024 +0000
 1 file changed, 3 deletions(-)
Introduction to Git

Příznaky git revert

  • Bez otevření textového editoru
    git revert --no-edit HEAD
    

 

  • Vrácení bez commitu (přesun souborů do oblasti staging)
    git revert -n HEAD
    
Introduction to Git

Vrácení jednoho souboru

  • git revert pracuje s commity, ne s jednotlivými soubory

  • Vrácení jednoho souboru:

    • git checkout
    • Použijte hash commitu nebo syntaxi HEAD
git checkout HEAD~1 -- report.md
Introduction to Git

Kontrola checkoutu

git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)

        modified:   report.md
Introduction to Git

Vytvoření commitu

git commit -m "Checkout previous version of report.md"
[main daa6c87] Checkout previous version of report.md
 1 file changed, 1 deletion(-)
Introduction to Git

Odebrání souboru ze stagingu

Čtyři soubory v repozitáři, z nichž tři jsou přidány do oblasti staging: report.md, mental health survey.csv a summary statistics.csv

Introduction to Git

Odebrání souboru ze stagingu

Summary statistics je přesunut z oblasti staging zpět do repozitáře

Introduction to Git

Odebrání jednoho souboru ze stagingu

  • Odebrání jednoho souboru ze stagingu:
git restore --staged summary_statistics.csv
  • Úprava souboru
git add summary_statistics.csv
git commit -m "Adding age summary statistics"
Introduction to Git

Odebrání všech souborů ze stagingu

  • Odebrání všech souborů ze stagingu:
git restore --staged
Introduction to Git

Shrnutí

Příkaz Výsledek
git revert HEAD Vrátí všechny soubory z daného commitu
git revert HEAD --no-edit Vrátí bez otevření textového editoru
git revert HEAD -n Vrátí bez vytvoření nového commitu
git checkout HEAD~1 -- report.md Vrátí jeden soubor z předchozího commitu
git restore --staged report.md Odebere jeden soubor z oblasti staging
git restore --staged Odebere všechny soubory z oblasti staging
Introduction to Git

Pojďme si to procvičit!

Introduction to Git

Preparing Video For Download...