git概论

感谢:http://www.cnblogs.com/atyou/archive/2013/03/11/2953579.html

git,一个非常强大的版本管理工具。Github则是一个基于Git的日益流行的开源项目托管库。Git与svn的最大区别是,它的使用流程不需要联机,可以先将对代码的修改,评论,保存在本机。等上网之后,再实时推送过去。同时它创建分支与合并分支更容易,推送速度也更快,配合Github提交需求也更容易。

Git全局设置

git config --global user.name "Your Name"
git config --global user.email youremail@email.com

将Git项目与Github建立联系

mkdir yourgithubproject
cd yourgithubproject
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:yourgithubname/yourgithubproject.git
git push origin master

导入现有的Git仓库

cd existing_git_repo
git remote add origin git@github.com:yourgithubname/yourgithubproject.git
git push origin master

git最主要的命令

add        Add file contents to the index  
bisect     Find by binary search the change that introduced a bug  
branch     List, create, or delete branches  
checkout   Checkout a branch or paths to the working tree  
clone      Clone a repository into a new directory  
commit     Record changes to the repository  
diff       Show changes between commits, commit and working tree, etc  
fetch      Download objects and refs from another repository  
grep       Print lines matching a pattern  
init       Create an empty git repository or reinitialize an existing one  
log        Show commit logs  
merge      Join two or more development histories together  
mv         Move or rename a file, a directory, or a symlink  
pull       Fetch from and merge with another repository or a local branch  
push       Update remote refs along with associated objects  
rebase     Forward-port local commits to the updated upstream head  
reset      Reset current HEAD to the specified state  
rm         Remove files from the working tree and from the index  
show       Show various types of objects  
status     Show the working tree status  
tag        Create, list, delete or verify a tag object signed with GPG 

日常提交常用命令

git add .
git commit -a -m"some files"
git push yourgithubproject

git init
创建一个数据库。
git clone
复制一个数据到指定文件夹
git add 和 git commit
把想提交的文件add上,然后commit这些文件到本地数据库。
git pull
从服务器下载数据库,并跟自己的数据库合并。
git fetch
从服务器下载数据库,并放到新分支,不跟自己的数据库合并。
git whatchanged
查看两个分支的变化。
git branch
创建分支,查看分支,删除分支
git checkout
切换分支
git merge
合并分支,把目标分支合并到当前分支
git config
配置相关信息,例如email和name
git log
查看版本历史
git show
查看版本号对应版本的历史。如果参数是HEAD查看最新版本。
git tag
标定版本号。
git reset
恢复到之前的版本
----mixed 是 git-reset 的默认选项,它的作用是重置索引内容,将其定位到指定的项目版本,而不改变你的工作树中的所有内容,只是提示你有哪些文件还未更新。
--soft 选项既不触动索引的位置,也不改变工作树中的任何内容。该选项会保留你在工作树中的所有更新并使之处于待提交状态。相当于再--mixed基础上加上git add .
--hard 把整个目录还原到一个版本,包括所有文件。
git push
向其他数据库推送自己的数据库。
git status
显示当前的状态。
git mv
重命名文件或者文件夹。
git rm
删除文件或者文件夹。
git help
查看帮助,还有几个无关紧要的命令,请自己查看帮助


github网上参与项目协作

 

帮助参考官方文档:https://help.github.com/articles/fork-a-repo

1.A账号登录github上,参与B账号的项目,在B账号网页上点fork
2.把项目clone到本地
  git clone https://github.com/A/xxx.git
3.添加上游远端GIT
  git remote add upstream https://github.com/B/xxx.git
  upstream可以随便取别名
4.取远端最新代码,保证自己的代码是最新,免得跟别人的有冲突
  git fetch upstream

5.合并到本地
  git merge upstream/master

6.更新远端自己的代码库(push Update remote refs along with associated objects)
  git push 
7.登录自己的账号A,在上面点pull request
  https://github.com/A/xxx

 
原文地址:https://www.cnblogs.com/kimsimple/p/7623045.html