Upgrade to Pro — share decks privately, control downloads, hide ads and more …

May the git --force be with you

May the git --force be with you

Talk discussing Git workflow and the controversial --force flag

Derrick Parkhurst

August 06, 2014
Tweet

More Decks by Derrick Parkhurst

Other Decks in Technology

Transcript

  1. You cannot control it. This is a dangerous time for

    you, when you will be tempted by the Dark Side of the Force.
  2. Git Checkout Checkout a branch $ git checkout {branch name}

    List all branches in the repository $ git branch Create a new branch $ git checkout -b {new branch name}
  3. git add Add a fle to the Staging Area $

    git add Add all modifed fles to the Staging Area $ git add -a
  4. Git Commit Edit commit message in your editor $ git

    commit Commit message on command line $ git commit -m 'adds some functionality' Each commit gets a SHA (long or short) d670460b4b4aece5915caf5c68d12f560a9fe3e4
  5. Git Commit --> git commit -m 'my commit message' [master

    92efac1] my commit message 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 config.yaml create mode 100644 script.rb
  6. git status --> git status On branch master Your branch

    is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: script.rb Untracked files: (use "git add <file>..." to include in what will be committed) config.yaml
  7. git diff Compare working directory (unstaged changes) to last comm

    $ git diff Compare staged changes to last commit $ git diff --cached
  8. git diff --> git diff diff --git a/confg.yaml b/confg.yaml index

    e69de29..81bf67e 100644 --- a/confg.yaml +++ b/confg.yaml @@ -0,0 +1,3 @@ +--- +frst_name: "Luke" +last_name: "Skywalker"
  9. git reset To unstage a fle (fles that have not

    been committed) $ git reset {SHA} {flename} Reset a single fle from the head of the current branch $ git reset HEAD benchmarks.rb Reset all fles from the head of the current branch $ git reset HEAD
  10. git checkout Retrieve a committed fle and place it in

    your working directory $ git checkout {SHA} {flename} Retrieve a fle from the HEAD of the current branch $ git checkout benchmarks.rb Retrieve a fle from any commit in the repository $ git checkout 085bb3b benchmarks.rb
  11. git log --> git log commit 92efac1f814b2a02b554ac694792f51488ca2762 Author: Derrick Parkhurst

    <[email protected]> Date: Tue Aug 5 23:54:38 2014 -0500 my commit message commit ca82a6dff817ec66f44342007202690a93763949 Author: Derrick Parkhurst <[email protected]> Date: Mon Mar 17 21:52:11 2008 -0700 changed the version number commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 Author: Derrick Parkhurst <[email protected]> Date: Sat Mar 15 16:40:33 2008 -0700 removed unnecessary test code
  12. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C1 C2 C1 C2 $ git checkout feature_branch $ git checkout feature_branch
  13. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C1 C2 $ git commit
  14. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C3 C1 C2 $ git push
  15. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C3 C1 C2 C3 $ git pull
  16. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C3 C1 C2 C3 C4 C5 $ git commit
  17. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C3 C4 C5 C1 C2 C3 C4 C5 $ git push
  18. Working in teams Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C4 C5 C1 C2 C3 C4 C5 C1 C2 C3 C4 C5 $ git pull
  19. git amend $ git add somefle.rb $ git commit -m

    'third commit' C1 C2 C3 Feature Branch
  20. git amend $ git add somefle.rb $ git commit $

    git add forgotten.rb $ git commit --amend *** This creates a new commit *** C1 C2 C4 Feature Branch C3
  21. git log mess commit e36c9e65189b79fe9d3d60473a59a54de181fbc8 refactor based on code review

    commit 8b2716e0151ed6efaa1c0789b5e8920d9481fe5c make broken test pass commit cd55e5b78d1339927fef898f8f51f6ac688027bb fx typo commit 92efac1f814b2a02b554ac694792f51488ca2762 Added new feature
  22. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C3 C1 C2 $ git push
  23. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C3 C1 C2 C3 C1 C2 C3 $ git pull
  24. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C4 C1 C2 C3 C1 C2 C3 $ git amend
  25. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C4 C5 C1 C2 C3 C1 C2 C3 C6 $ git commit $ git commit
  26. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C4 C5 C1 C2 C4 C5 C1 C2 C3 C6 $ git push --force
  27. Warning! Rewriting History Dev 1's Repository Origin Repository Dev 2's

    Repository C1 C2 C4 C5 C1 C2 C4 C5 C1 C2 C3 C6 $ git pull
  28. git reflog --> git reflog • bf0715c HEAD@{0}: commit (amend):

    refactor based on code review • e36c9e6 HEAD@{1}: commit: refactor based on code review • 8b2716e HEAD@{2}: commit: make broken test pass • cd55e5b HEAD@{3}: commit: fix typo • 92efac1 HEAD@{4}: commit: my commit message
  29. Work only on independent branches Use developer branches off of

    feature branches C1 C2 C3 Master C4 Feature C5 C6 C8 C10 Developer 1 Developer 2
  30. Quality commit messages Short (50 chars or less) summary of

    changes More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical Use the imperative present tense in these messages. In other words, use commands. Instead of "I added tests for" or "Adding tests for," use "Add tests for."
  31. Quality commits Do: – Logically separate content – Commit changes

    and tests together – Don't: – Commit fixups or refactorings Facilitates: – Code review – Reverting changes later in time – Testing and debugging
  32. Midi-chlorians $ git add -p $ git stash $ git

    rebase -i – Reword – Reorder – Combine – Split – Insert – Delete