最近项目需要用Git,上网找资料快速学习,找到一个非常非常不错的网址如下:
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
Create the local repository:
git init
git add readme.txt
git commit -m "create the readme.txt"
git status
git diff readme.txt
Undo and Redo:
git log
git log --pretty=oneline
git reset --hard HEAD~1 - recover to the last version
git reset --hard 3628164 - recover to the specified version
git reflog
git checkout -- readme.txt - recover the working area to the committed version
git reset HEAD readme.txt - recover the stage area to the committed version
Delete the file:
rm test.txt
git rm test.txt
git commit -m "remove test.txt"
git checkout -- test.txt - recover the deleted file
Create the remote repository:
git remote add origin git@github.com:baominwang/learngit.git
git push -u origin master
git push origin master
Clone from the repository:
git clone git@github.com:baominwang/gitskills.git
Create the branch:
git checkout -b dev - create and switch to the dev branch
git branch - check the branch
git checkout master - switch to the branch
git merge dev - merge the branch
git branch -d dev - remove the branch
Fix the branch conflict:
git merge dev
git merge --no-ff -m "merge with no-ff" dev - merge without "fast forward"
git log --graph --pretty=oneline --abbrev-commit
Fix the bug:
git stash - backup the current working area
git stash list
git stash list - recover the working area, but the stash is still there
git stash pop - recover the working area, but the stash is removed
git stash apply stash@{0} - recover with the specified stash
Co-Working:
git remote
git push origin master
git push origin dev - push the dev branch
git checkout -b dev origin/dev - create the dev branch in local
git branch --set-upstream dev origin/dev - link the local branch to the remote branch
git pull