Git

Summary

Branch

  • git branch, list of local branch- git branch -a, list of all branch
  • git branch @newBranchName, create @newBranchName based on current branch
  • git branch --set-upstream-to=origin\/master master, link local branch master to remote branch master
  • git checkout @branchName, swith to @branchName
  • git checkout tags/@tagName -b @branchName, create a new branch with tag name.
  • git branch --delete @branchName, delete local branch
  • git push origin --delete @branchName, delete remote branch
  • git checkout @sha, checkout a particular commit.

Pull

  • git pull @remoteRepos @branchName, fetch and commit changes from @remoteRepos\/@branchName to local localRepos\/branch
  • git pull https:\/\/github.com\/shuoshuorili\/smartv-ios.git master, fetch and commit changes from github repos to local.

Compare

  • git diff @branch1 @branch2 -- a.txt, compare a.txt between @branch1 and @branch2
  • git diff, compare the working copy with the index
  • git diff --cached, compare the index with HEAD
  • git diff HEAD, compare the working copy with HEAD

Undo

  • git checkout HEAD a.txt b.txt, revert changes in a.txt and b.txt
  • git checkout HEAD *.txt, revert changes in all txt files
  • git checkout HEAD, revert all changes

Commit

  • git commit -m "commit message", commit all files
  • git commit -m "commit message" a.txt, commit a.txt
  • git commit -C head -a --amend, add new changes to an exist commit without generating new commit
  • git reset --soft HEAD~1, undo the last commit

Merge

  • git merge @branchName, merge changes from @branchName to current branch, if no conflict, auto commit it.
  • git cherry-pick @commit-hash, apply commit to current branch

Merge local uncommitted changes into another branch

  • git stash, zip- git checkout @branchName, switch to @branchName- git stash pop, unzip

Submodule

  • git submodule add https:\/\/github.com\/ybbaigo\/FSCalendar.git FSCalendar, add submodule to FSCalendar under current folder
  • git submodule update --init --recursive, go to submodule folder and run this command to checkout

Revert 2 commits on master branch

  • git reset --soft HEAD~2
  • git push origin +master

Generate ssh keys on Github

https://help.github.com/articles/generating-ssh-keys/

results matching ""

    No results matching ""