Git 常用命令

最近项目需要用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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值