git常用commands

来源:互联网 发布:微信分销源码 编辑:程序博客网 时间:2024/05/16 09:17

 

1. initialize git: git init

2. add file to index: git add filename

see difference: git diff --cached ( 在commit之前可以看cache中文件和现有文件的区别)

3. commit: git commit

git commit -a可以省去之前的git add filename一步,但是对于新添加文件不奏效,如果modify了一个文件,就可以直接commit -a

4. git status

5. git log 或者 git log --graph

git log -p( can see complete change at each step)

6. git help command

7. gitk

8. git gui

9. git blame filename (看文件中每行代码谁修改过)

10. git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7

git show HEAD (the tip of current branch)

git show experimental (the tip of the experimental branch)

git show HEAD^

git show HEAD^^

git show HEAD~4

git show HEAD^1 (note that merge commits may have more than one parent, 1 means show the first parent)

11. git tag v2.5 HEAD

12. git diff v2.5 HEAD

13. git branch stable v2.5 #start a new branch named "stable" based at v2.5

14. git reset --hard HEAD^ #reset current branch and working directory to its state at HEAD^

15. git grep "hello" (v2.5 #不指明的话,会搜索当前目录下的所有文件)

16.

$ git log v2.5..v2.6            # commits between v2.5 and v2.6


$ git log v2.5.. # commits since v2.5


$ git log --since="2 weeks ago" # commits from the last 2 weeks


$ git log v2.5.. Makefile # commits since v2.5 which modify makefile




17. git log stable..master #list commits in the master branch but not in the stable branch

18. gitk --since="2 weeks ago" drivers/

19. git diff v2.5:makefile HEAD:makefile.in

20. git show v2.5:makefile

 

manage branch

1. git branch experiment : create a new branch named experiment

2. git branch : see all branches, the current brach is marked

3. git checkout experiment : switch to branch "experiment"

4. git merge experiment : manually handle conflicts

5. git branch -d experiment : it will make sure the changes in branch experiment are already in the current branch (say master)

6. git branch -D experiment: delete anyway


using git for collaboration

1. 第一次扒数据: git clone url (git clone /home/alice/project  or git clone git@143.89.126.***:~/FindBugs)

2. 然后本地就有了repository

3. git pull /home/bob/myrepo master 同步

4. 如果想先看下变化再进行merge可以用fetch(fetch来的数据放在cache中)

git fetch /home/bob/myrepo master

git log -p HEAD..FETCH_HEAD(see changes)

gitk HEAD..FETCH_HEAD (有界面)

gitk HEAD..FETCH_HEAD (view what both of them did since they forked)

5. git remote add bob /home/bob/myrepo


configuration

git config (--global) user.name "your name"

git config (--global) user.email andrew@gmail.com

 

原创粉丝点击