见过最好的git入门教程 .

来源:互联网 发布:淘宝刷流量有用吗 编辑:程序博客网 时间:2024/06/11 15:46

http://blog.csdn.net/voluptas/article/details/6339855

 

今天找到一篇见过最好的git入门教程

http://lostechies.com/joshuaflanagan/2010/09/03/use-gitk-to-understand-git/

 

粘帖一些命令

1. git add 添加文件到staged area.
2. git commit 会commit staged file ,有几个选项比较重要:-a 跳过staged area,直接commit,后面加文件名也会使那个文件跳过stage,直接commit。但是前提是文件已经在index中了,新文件不会自动加入。
3.git status 查看从上次commit到目前的变化,git diff会更详细,但是它只包含应该要包含在staged area中却还未包含进去的变化,git diff --staged则列出来从上次commit到staged area的变化。
4. .gitignore文件可以设置哪些文件被排除进去,通常可以设.o, .a等文件。
5. git rm 用来remove文件。
6. git mv可以用来重命名文件。
7. git log用来查看日志,git log -p查看详细,gitk 是个图形化的查看工具。
8.Unstaging a Staged File可以用git reset HEAD <file>。 Unmodifying a Modified File可以用git checkout -- <file>。git commit --amend用来取消上次的commit。
9. git remote显示所有的remote(加-v显示详细信息)。
git remote add [shortname] [url]用来添加remote。git fetch [remote-name]只会pull下来全部的更动,但不会自动merge,但是git pull会自动merge。 git remote show [remote-name]可以看到一个remote的详细信息。 git remote rename用来改变一个remote的名字。git remote rm删除一个remote。
10.git tag列出所有的tag。git show tag-name可以查看tag详细信息。git tag [-a] tag-name -m message [commit-checksum]如果有-a 就添加一个annotated tag,如果没有-a,就添加一个lightweight tag,如果后面要在某个commit之后添加一个tag,就加上checksum好了。 git push有个选项 --tags会把tags信息也push上去。

11.
git branch testing添加一个testing的branch. git checkout testing切换到testing branch.
12. 切换branch的时候,当前的branch不能有和要切换过去的branch冲突的uncommitted changes.
13. git merge branch-name 将branch-name merge到当前branch.如果有conflict,可以用status查看状态,解决conflict之后用add 通知git已经解决。然后用commit commit the merge。
14.
  git branch -d branch-name,但是这个branch必须被全部merge到HEAD中了。如果选项是-D的化,就不管它的merge status了。
15. git branch --merged只显示被HEAD完全包含的branch,--no-merged只显示没被HEAD完全包含的branch。
16.
git push (remote) (branch)把本地某个branch push到remote上去。 git push (remote) (local-branch-name):(remote-branch-name)可以把本地branch push到remote branch上去。
17.git fetch 下载下来的branch不能edit,必须要手动merge到本地branch之后才可以edit。
  $ git checkout -b local-branch-name remote-name/remote-branch-name 可以把server上的branch下载下来,并且可以直接edit。
18.
Tracking Branches里面可以不必在pull和push后面加remote参数。git branch -r列出remote tracking branches.
19. git push [remotename] :[remote-branch]删除掉某个remote branch。
20. rebase可以获得和merge一样的效果,但是log记录更好,因为看起来没有分支。
git rebase --onto newbase upstream branch会把从upstream到branch的改动rebase到newbase上去。git rebase basebranch topicbranch会把topicbranch rebase到basebranch上。
21.
Do not rebase commits that you have pushed to a public repository.

22.git fetch默认会获取repo所有branch的进度,除非指定哪个branch。git push可以将某个branch push到repo中去。

 

0 0
原创粉丝点击