2017年4月11日 星期二

Git commands

  • Settings
    • git config --global user.name "Your name"
    • git config --global user.email "Youremail@xxx.xx"
    • git config --global core.editor "vim"
  • Checking & Help
    • git config --list
    • git help
    • git help add
  • Create local repository and initial the project.
    • cd FirstApp
    • git init
    • git add * or git add *.java or git add AndroidManifast.xml
    • git add .gitignore
    • https://github.com/github/gitignore
    • git commit -m "Initial Project Version"
    • git status
    • change a file,  i.g AndroidManifast.xml
    • git diff  // diff the file in working sapce
    • git add AndroidManifast.xml
    • git diff --cached // diff the file in staged state
    • git commit -a -m "Change comment added 2"  
    • git add DeletedMe.txt
    • git rm -f DeleteMe.txt  // -f will remove from staged state and also delete file from workspace
    • git rm --cached DeleteMe.txt // it just remove from staged state, the file still exist
    • git mv DeleteMe.txt Delete.txt // rename the file name.
    • git log --pretty=oneline
    • git log --pretty=format:"%h : %an : %ar : %s" // abbreviation, author, time, comment
    • git log
    • git log -p - 2 // show last two changes
    • git log --stat
    • git log --since=1.w
    • git log --since="2014-04-12"
    • git log --author="Author name"
    • git log --before="2014-04-13"
  • Undo comment
    • git add DeleteMe.txt
    • git commit -m "Random Change"
    • git commit --amend // allow you to undo previous comment.
  • Un-staged the file
    • git add Delete.txt
    • git reset HEAD Delete.txt
  • Git, remote, Repositories, GitHub, Push, Pull, aliases and Tags
    • cd FirstApp
    • git init
    • git add .
    • git commit -m "First Project Version"
    • git remote add origin https://github.com/youraccount/your_project_on_git_hub
    • git push origin master  // then input the account and password on github
    • git remote -v
      • origin https://github.com/youraccount/xxx.git (fetch)
      • origin https://github.com/youraccount/xxx.git (push)
    • git fetch origin
    • git pull https://github.com/youraccount/xxx.git
    • git add .gitignore
    • git commit -m "Add .gitignore for Android"
    • git add Andoridmanifest.xml
    • git commit -m "Changed Android Manifest Comment"
    • git push
    • git remote -v 
      • origin https://github.com/youraccount/xxx.git (fetch)
      • origin https://github.com/youraccount/xxx.git (push)
    • git remote rename origin sf
    • git remote -v 
      • sf https://github.com/youraccount/xxx.git (fetch)
      • sf https://github.com/youraccount/xxx.git (push)
    • git tag  // to check all tag in current branch
    • git tag -a v0.2 -m "Version v0.2"
    • git show v0.2
    • git push sf v0.2   // push single tags onto github, you can check release tab to see the information on github websit.
    • git push sf --tags  // push all tags onto github
  • Create a short cut command
    • git config --global alias.co commit
    • git add .
    • git co -m "Demostrate Alias"
  • git clone 
    • cd google_pacman
    • git clone https://github.com/xxxxx/google_pacman.git
  • branch
    • git branch fix20          // create fix20 branch
    • git checkout fix20      // switch to fix20 branch
    • git checkout -b fix20  // create fix20 branch and switch to it
    • git checkout master    // switch to main branch 
    • git push origin fix20   // push the branch onto github, you can check branch tab on github website.
    • git checkout -b fix20 origin/fix20  // pull the fix20 branch from github
    • git branch  // check the branch status
      • fix20
      • *master
    • git branch --merged   // check merged branch
    • git branch --no-merged  // check unmerged branch
    • git branch -v
    • git merge fix20
    • git branch -d fix20 // delete fix20 branch, delete the merged branch
    • git branch -D fix20 // delete fix20 branch which is unmerged.
    • git push origin :fix20  // delete fix20 branch on github

  • git branch: check current local Repo branches
    i.e:
    $git branch
    master

  •  git branch -r : check remote repo branches
    i.e:
    $git branch -r
    origin/HEAD -> origin/master
    origin/cleanup
    origin/master

  • git checkout -b <local branch name> <remote branch name>
    i.e:
    $git branch -b cleanup origin/cleanup
    Use git branch to check current branch on your local repo 

  • git checkout <local branch name>: switch local branch
    i.e:
    $git branch
    *cleanup
    master

    '*' indicate which branch you are using
    $git checkout master $git branch cleanup
    *master
    Now you are using master branch.

沒有留言: