Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Git Survival Tips: How to Undo and Recover from Your Mistakes

255 Aufrufe

Veröffentlicht am

We can’t avoid mistakes altogether, but the right tools can make sure they don't hurt us too much. Git offers many ways to undo, revert, recover and fix your mistakes. In this session, we'll look at the bad things that can happen to you—and how Git can save your neck. If you’d like to gain more confidence in your day-to-day operations when working with code, I’ll show you how to deal with mistakes in real-world scenarios with Git's various “undo features,” using both the command line and the popular GUI, Tower.

Veröffentlicht in: Software
  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

Git Survival Tips: How to Undo and Recover from Your Mistakes

  1. 1. Git Survival Tips Tobias Günther www.git-tower.com How to Undo & Recover from Your Mistakes
  2. 2. Mentioned product names and logos are property of their respective owners.
  3. 3. Making changes in a complex software project
  4. 4. Undoing Local Changes
  5. 5. Undoing Local Changes $ git checkout HEAD <filename> $ git reset --hard HEAD Discarding uncommitted local changes cannot be undone!
  6. 6. Undoing Committed Changes fix a typo in your last commit revert a commit in the middle restore the project at an earlier version
  7. 7. Amending Your Last Commit Mistyped the commit message… …and/or forgot to add a change.
  8. 8. Reverting Commits Modifies “index.html” in the “opposite” way: (old) <div>About</div> (new) <div>About This Project</div> Modified “index.html”: (old) <div>About This Project</div> (new) <div>About</div> Reverting Commit “git revert” creates a new commit (C4) that reverts the effects of a specified commit (C2).
  9. 9. Resetting HEAD (aka “Rollback”) master HEAD master HEAD Before reset After reset “git reset” sets your HEAD pointer (and thereby also your working copy) to an older revision. Commits that came after this revision appear to be undone.
  10. 10. Undoing Committed Changes $ git add forgotten_change.txt $ git commit --amend -m “Correct message” $ git revert e81fc22 $ git reset --hard e81fc22
  11. 11. Recovering “Lost” Commits master HEAD master HEAD1. You think you want to reset. 2. You reset. 3. You notice it was a bad idea. 4. You panic. — An Example —
  12. 12. Recovering “Lost” Commits git reflog a journal that logs every movement of the HEAD pointer
  13. 13. Dealing with Merge Conflicts OMG! Help!
  14. 14. Dealing with Merge Conflicts don’t panic! 1. Git deals with most of the stuff. 2. You only ever handicap yourself (not your team). 3. You can always undo and start fresh. — You Cannot Break Anything —
  15. 15. Dealing with Merge Conflicts — How a Conflict Happens — Modifies line 16 in “about.html”: (old) <div>About</div> (new) <div>About Us</div> Modifies the same line in in the same file: (old) <div>About</div> (new) <div>About Tower</div> contact-form master HEAD merge conflict
  16. 16. Dealing with Merge Conflicts — What a Conflict Really Is — 1.Two contradictory versions (“A” and “B”) of a file. 2.…just funny letters in a text file.
  17. 17. Dealing with Merge Conflicts Who made the changes? When? On which branches? In which commits? … — Understanding What Happened —
  18. 18. Dealing with Merge Conflicts — Solving a Conflict — (a) Use your editor / IDE to modify the file by hand. (b) Use a Merge Tool. (c) Use Tower / Git in easy cases. = deciding, how it should finally look
  19. 19. Dealing with Merge Conflicts — Wrapping Up — 1. Save 2. Stage / Add 3. Commit = mark as resolved (might already be done by external tool)
  20. 20. Get in Touch! Learning Platform: www.git-tower.com/learn/ Twitter: @gittower Email: support@git-tower.com

×