初心者 Git 上手攻略

  • View
    4.418

  • Download
    4

Embed Size (px)

DESCRIPTION

Cloud Computing-Based Services Design and Programming 2014S Git Tutorial For the Beginner

Transcript

  • Git Cloud Computing-Based Services Design and Programming Lucien Lee
  • First,letMeTellyouaStory 2
  • work alone 3
  • 4
  • workwithothers 5 BYDropbox,right?
  • 6
  • Does it sounds happened to you before? 8
  • AllYouNeeDis__________ 9 Version Control
  • 12 What to fear are not the God-like opponents but the goose-like teammates.
  • git: Distributed Version Control Systems 13
  • 1. SET UP YOUR Git
  • Windows Mac Homebrew brew install githttp://msysgit.github.io/ git for windows SourceTree https://help.github.com/articles/set-up-git GUI github app
  • $ git config --global user.name $ git config --global user.email $ git config --global color.ui true 17
  • // under your project $ git init 18 git .git
  • .gitignore basic Git in Local
  • 20 s tIworking directory staging area repository .git status commit
  • $ git status On branch master nothing to commit, working directory clean 21 git
  • 22 s tIworking directory staging area repository stage les commit
  • // From working directory to staging area $ git add ! // From staging area to working directory $ git reset HEAD 23
  • // commit to repo $ git commit $ git commit -m commit message ! // get commit from repo to staging area $ git reset soft HEAD^ 24
  • Take a snapshot Commit 25
  • $ git log 26 git log
  • 27 s tIworking directory staging area repository untracked unmodied modied staged add les commit edit les stage les
  • #Untracked files $ git add #Changes not staged for commit $ git add 28 git Add git add
  • $ git diff 29 git diff
  • $ git rm 30 git rm repo
  • .gitignore add C/C++ binary add .gitignore *
  • $ git reset hard 32 code commit
  • $ git checkout 33 commit
  • Push and Pull git with remote repository
  • 35 s tIworking directory staging area repository ytremote repository
  • 36 s tIworking directory staging area repository ytremote repository s tIworking directory staging area repository ssh public key
  • remote Repo service Cooperate with others, private used or open source Issue tracking, Wiki feature Over 5 people in a private repo will charge In this course, we use github and open source
  • SSH: Secure Shell 38 yt 1. o2. 3. public key private key
  • set up ssh key with gitgub 39 Reference: https://help.github.com/articles/generating-ssh-keys
  • $ cd ~/.ssh $ ls -al # Lists the files in your .ssh directory 40 Step 1: Check for SSH keys id_rsa.pub or id_dsa.pub
  • $ ssh-keygen -t rsa -C "your_email@example.com" # Creates a new ssh key, using the provided email as a label 41 Step 2: Generate a new SSH key ssh key /.ssh/
  • #mac $ pbcopy < ~/.ssh/id_rsa.pub #windows $ clip < ~/.ssh/id_rsa.pub 42 Step 3: Add your SSH key to GitHub Gitbub
  • Step 3: Add your SSH key to GitHub 43
  • 44 t yt repo repo t yt repo remote repo remote reporepo 1. 2.
  • $ git remote add origin git@HOSTPATH 45 repo repo
  • github repo 46
  • $ git clone git@HOSTPATH:directory name 47 repo repo
  • $ git remote -v 48 git remote repo
  • $ git remote add [shortname] [url] 49 git remote add origin repo
  • push and pull 50 t yt push: pull:
  • $ git push origin master 51 git push () master master
  • $ git pull origin master 52 git pull
  • branch
  • Branch 54
  • $ git branch 55 git Branch
  • What branch look like branch branch 56
  • #list local branch $ git branch #list local and remote branch $ git branch -a #delete the branch $ git branch -D 57 Manipulate branch
  • $ git checkout 58 change your branch
  • $ git checkout -b 59 New and change branch simultaneously
  • What branch look like 60
  • Detached Head checkout commit branch Git branch
  • $ git log commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 Author: Scott Chacon Date: Sat Mar 15 16:40:33 2008 -0700 ! removed unnecessary test code ! commit a11bef06a3f659402fe7563abf99ad00de2209e6 Author: Scott Chacon Date: Sat Mar 15 10:31:28 2008 -0700 ! first commit $ git checkout a11bef0 62 checkout to past commit
  • merge 63
  • merge auto merge GG conict 64
  • $ git merge 65
  • conflict git status git add git commit
  • $ git status On branch master You have unmerged paths. (fix conflicts and run "git commit") ! Unmerged paths: (use "git add ..." to mark resolution) ! both modified: index.html 67 conflict
  • > bugFix 68
  • $ git commit -am Merge bugFix 69 commit
  • $ git reset --hard 70 Merge conict merge commit
  • $ git checkout ours $ git checkout theirs 71 Merge conict conict branch ours theirs
  • 72
  • git branch master dev git fetch origin
  • git flow http://nvie.com/ posts/a-successful- git-branching- model/
  • 75 https://guides.github.com/introduction/ow/index.html
  • Git stash appendix
  • #mac brew install git bash-completion #Ubuntu/Debian sudo apt-get install git-core bash-completion 77 Bash shell git
  • $ git config --global alias.co checkout $ git config --global alias.br branch $ git config --global alias.ci commit $ git config --global alias.st status 78 git