add,commit ,log ,reset

  1. git add =>specified single file
  2. git add . =>to add all file
  3. git commit -m "your message" =>commit with message
  4. git commit -a-m "your message" => the '-a' symbol only add modified or deleted tracked file,modifed or deleted file is no need more to use "git add"
  5. git commit --amend =>change the messge you have commited
  6. git status ==> file status
  7. git diff ==>difference
  8. git log ==>check history version
  9. git log --pretty=oneline ==>pretty show
  10. git reset --hard version id ==>reset to specified version,even is desprecated version if you still know the version id
  11. git reflog ==>to show every command you have write (to find the version you have lost )

notice the difference between the check out branch

  1. git checkout -- ==> give up the change of the specific file at the workspace, and if you have delete some file wrong ,you can replace the workspace contents with the local repository contents

  2. git checkout . ==>give up all the changes at the workspace

  3. git reset HEAD file ==> to reset the stage content to workspace

  4. git rm ==>delete the file at the local repository

  5. git remote add origin https://github.com/xxx/xxx.git ==> connect local repository to remote

  6. git push -u origin master ==> push local master branch to remote first time

  7. git push origin master ==>push local master branch to remote after first time, need to connect local branch to remote

the branch is only to check your daily work

  1. git checkout -b dev ==> create and switch to dev branch

  2. git branch ==> check all the branch

  3. git brach -a ==>branch local and remote

  4. git checkout brachName ==> switch to brachName branch, when switch branch please commit your change first

  5. git merge dev ==>merge the dev to current branch

  6. git merge --no-commit branchName ==> merge brachName to current brach

  7. git branch -d dev ==>delete the dev branch,you’d better delete it after you merge to master

  8. git branch -D branchName ==>delete forced

  9. git push origin dev:dev_remote ==>create remote new branch(dev is your local branch)

  10. git push origin test:master ==> push test to remote master(as master)

  11. git push origin :test ==>delete remote test branch

  12. git push origin --delete test ==>delete remote test branch

  13. git checkout origin/remote_branch_name ==> checkout remote branch

  14. git clone xxx.git "filepath" ==>specify the filepath where you want to clone

  15. git pull origin : ==> if local branchName is nil,default to be local current branch

  16. git pull is equal to git fetch + git merge origin branch to current

  17. git merge --no-ff -m "merge with no-ff" dev ===>merge dev to current branch and forbid "fast forward"mode add will commit with a new message

  18. git stash ==>save current branch working space and the work space will be clean,function to create a new branch to fix some bug,and not to commit the workspace work that not finished

branch remote and local

  1. git remote -v ==>check remote branch link info
  2. git branch –r ==> check remote branch info
  3. git branch --set-upstream branch-name origin/branch-name ==> if pull failed ,this command will connect local branch with remote appropriate branch

git tag:replace commit id with tag will be much more easy

  1. git tag ==> add a tag name

  2. git tag default tag at latest commit,this will tag at specific commit

  3. git tag -a -m "message"

  4. git tag ==>show all tag

  5. git show ==>see the tag info,tag is not ordered by time but charactors

  6. git tag -d ==>delete a tag local,tag default not push to remote

  7. git push origin :refs/tags/ ==> if tag name is push to remote ,delete local first,then delete remote

  8. git push origin

  9. git push origin --tags ==>push all tags once

  10. git log --graph ==>see graphical of the branch merging