您的位置:首页 > 其它

git小抄[ZZ]

2014-01-13 15:58 232 查看
半年前給项目组写过一个git小抄[1],今天boboyang问起git的服务器设置和如何用git做团队内文档协作共享,我就把那份小抄稍作整理发给他,顺便贴在这里,或许也能有用。

0. git init: to create a git repository as a central server

#创建一个git库作为中心服务器节点。其实git是分布式的,可以不用中心节点,但有中心节点的模式对习惯于cvs、svn等工具的同学来说较易理解。

> mkdir myrepo.git && cd myrepo.git

> git init --bare

1. git clone: to check out the src

#从服务器克隆一个git库到本地

> cd /my/working/area

> git clone /path/to/myrepo.git

#此处假设myrepo.git夜是在当前这台机器上。如果是在另一台机器上,则需要git clone ssh://the.server.address/path/to/myrepo.git

2. do your work: creating files, editing, etc.

#创建、修改文件

> cd myrepo # swb_pcie is called your working dir

> echo “Hello, world” > test.txt

3. git diff: to review your work

#查看本次修改

> git status # will show which files were modified

OR

> git diff # will show your modification as a patch;

# but untracked files are not listed

4. git add: to register your change to git

#告诉git你的修改。注意,这只是把修改的信息记录在本地的git里面。

> git add test.txt

5. git commit: to record your change in your LOCAL working directory

#提交本次修改。注意:这仅仅是把修改提交到本地的git,远端的服务器还那边完全不知道

> git commit # your’ll be prompted to write a comment for this commit

OR

> git commit -m “your brief comment” # this way is quicker

6. git log: to review the commit histories

#查看本地的提交历史

> git log # you will see all the commits

7. git fetch/pull: to sync with remote git repos

#从服务端同步数据

> git pull origin # will get updates others push

# onto the central git repo and merge

OR

> git fetch origin # will get updates, but not merge

> git merge origin/master # now merge.

# This 2-step approach allows

# you to examine the update before merging

# with sth like “git log origin/master”

#推荐用先git fetch再git merge的方法,建议不要直接git pull

8. git push: to push your work to remote git repos

#把本地的数据推送到服务端。注意,只有这一步之后,你的工作才能被他人看见,否则都是你在本地玩而已。

> git push origin

—-

[1]即cheat sheet,老美的说法,借用考试小抄的意思,指特别简单的入门指南

转载:http://blog.zjutoe.net
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: