git 常用命令

1. git config --global user.name wenhchen

          git config --global user.email "wenhui.chen@nokia-sbell.com"

          ssh-keygen [-t rsa]

          cat /c/Users/wenhchen/.ssh/id_rsa.pub

2. git add a.txt b.txt

          git add -u # only tracked files

          git add -A # all files include untracked files

3. git commit -m "modify a.txt"

          git commit --amend # modify the last commit

4. git log  # list commit history

git log a.txt # list a.txt commit history

git reflog # list all logs include deleted commit

5. git diff [--stat] commit_id1 commit_id2 # view the modify between two commits

6. git checkout -- a.txt # discard the modify of working dictory

git reset HEAD a.txt # move the modify from stage to working dictory

          git reset --soft commit_id # delete commit info, move the modify to stage

          git reset --mixed commit_id # delete commit info, move the modify to working dictory

          git reset --hard commit_id # delete commit info, and delete the modify

          git reset [--mixed] commit_id -- a.cpp # only modify the stage

7. git init # new an empty repo, only have .git dir

git clone xxx.git [dir] # clone one exist repo

8. git branch [-r/-a] # list branch

git branch xxx # create new branch based on current branch

git branch -d/-D xxx # delete branch

git checkout -b xxx # create and checkout new branch based on local branch

git checkout -b xxx origin/xxx # create and checkout new branch based on remote branch

9. git tag v.1.0 # create tag based on current commit

git tag v.1.0 commit_id # create tag based on specified commit

git tag # list tags

git show v.1.0 # show the tag commit info

git push origin v1.0 # push tag to remote

git tag -d v1.0 # delete local tag

git push origin :refs/tags/v1.0 # delete remote tag

10. git stash # save work directory and statge modify to stack

git stash apply # restore the modify in stack

11. git blam a.txt -L 3,5 # list the last commit info of line 3-5

git show commit_id # show commit info

12. git merge/rebase xxx # without conflict

13. git merge/rebase xxx # with conflict

14. git fetch # get all remote branch index

git push [-f] origin master # push commit to remote branch

git push origin :xxx # delete remote branch

git pull origin xxx # git fetch + git merge

git pull --rebase origin xxx # git fetch + git rebase

15. git clean -dxf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值