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

Learn Git

Learn Git

Git introduction, commands, tips and Github.

Lin Zhang

May 06, 2013
Tweet

Other Decks in Programming

Transcript

  1. Agenda • Git Introduction • Git Commands • Git Tips

    • Github 13年5月4⽇日星期六
  2. Git Introduction • Distributed Version Control System • Linux Torvalds

    created for Linux Kernel • 2005.4 released 13年5月4⽇日星期六
  3. My Version Control System • 2009 Subversion (co, ci, up)

    • 2011 Git (repo on private server) • 2012 Github, Bitbucket (pull request) 13年5月4⽇日星期六
  4. 脱离SVN苦海 git  svn  clone  -­‐-­‐stdlayout  -­‐-­‐no-­‐metadata  \   -­‐A  users.txt

     svn://hostname/path   dest_dir-­‐tmp http://stackoverflow.com/questions/79165/how-­‐to-­‐migrate-­‐svn-­‐ with-­‐history-­‐to-­‐a-­‐new-­‐git-­‐repository 13年5月4⽇日星期六
  5. 初试⽜牛⼑刀 • mkdir -p repo && cd repo • git

    init • touch README • git add README • git status • git commit -m ‘First Commit’ 13年5月4⽇日星期六
  6. 分⽀支合并 • git branch my-branch • git checkout my-branch •

    git rebase develop • git merge my-branch 13年5月4⽇日星期六
  7. 远程交互 • git remote add upstream <git-repo-url> • git fetch

    upstream • git pull upstream master • git push origin master 13年5月4⽇日星期六
  8. 还有很多... • git mv file • git rm file •

    git log • git diff • git reset --hard HEAD • git tag -a v1.0 -m ‘tagging v1.0’ 13年5月4⽇日星期六
  9. #Tip2 Manage Remote Branches • git checkout --track origin/branch •

    git branch -D local-branch • git push origin local-branch:remote-branch • git push origin :remote-branch 13年5月4⽇日星期六
  10. #Tip3 Amend on commit • with reset • git reset

    HEAD~ • update • git commit -am ‘some message’ • with amend • update • git commit -a --amend 13年5月4⽇日星期六
  11. #Tip4 Stash Local Changes Before Merge/Patch • git stash •

    git stash save ‘your message’ • git stash list • git stash pop • git stash apply stash@{0} • git stash drop stash@{0} • git stash clear 13年5月4⽇日星期六
  12. #Tip6 Push之前可以做的事 • git reset HEAD~2 • --soft • --hard

    • git amend -a --amend • git rebase -i HEAD~3 13年5月4⽇日星期六
  13. D---E master / A---B---C---F origin/master D--------E / \ A---B---C---F----G master,

    origin/master git pull origin master A---B---C---F---D'---E' master, origin/master git pull --rebase origin master 13年5月4⽇日星期六
  14. #Tip9 Recover your changes • git revert HEAD~ • git

    revert HEAD~1 --no-edit --mainline 2 13年5月4⽇日星期六
  15. 冲突类型及解决 • 逻辑冲突 • auto merged/patched • ⽂文件树冲突 • git

    mergetool • 内容冲突 • merge/patch • rebase 13年5月4⽇日星期六
  16. 什么是⼈人⾁肉合并 >.< • 干掉7个>,< • 卷⼟土重来 • git reset --hard

    HEAD • git merge --abort • git rebase --abort 13年5月4⽇日星期六
  17. Commit Guidelines • Commit related changes • Commit small and

    often • Dont commit half-done work • Test code before commit • Write good commit message 13年5月4⽇日星期六
  18. Branch Guidelines • Keep master branch always deployable • Develop

    features on new local branches • Stash you local changes when switch to another branch 13年5月4⽇日星期六
  19. Merge Guidelines • Merge more often and earyly • Merge

    with rebase • Test code before merge 13年5月4⽇日星期六
  20. Rebase Guidelines • Never rebase your master branch • Never

    rebase a published branch • Rebase your feature branches 13年5月4⽇日星期六
  21. feature, release, hotfix • git flow init -d • git

    flow feature start feature-x • git flow feature rebase • git flow feature finish feature-x 13年5月4⽇日星期六