Git分布式版本控制
Git 安装配置
Linux&Unix平台
Debian/Ubuntu $ apt-get install git Fedora $ yum install git (up to Fedora 21) $ dnf install git (Fedora 22 and later) Gentoo $ emerge --ask --verbose dev-vcs/git Arch Linux $ pacman -S git openSUSE $ zypper install git FreeBSD $ cd /usr/ports/devel/git $ make installSolaris 11 Express $ pkg install developer/versioning/git OpenBSD $ pkg_add git
Windows
官网下载地址:https://git-scm.com/download/win
MAC
下载地址:https://sourceforge.net/projects/git-osx-installer/
Git 配置
设置用户名称和电子邮件
git config --global user.name "lingdong" git config --global user.email "lingdong@wld5.com"
查看配置信息
git config --list
使用Git分布式版本控制系统工作流程
克隆数据到本地机器工作目录
在本地建立的分支,修改代码
在自己建立的分支上进行提交代码
修改完毕后把分支与主分支进行合并
推送本地代码到远程服务器
版本仓库管理员进行审核,使用允许推送
三大开源站点
SourceForge
codeplex
Github
Git常用命令
初始化&&克隆
git init git clone
建立项目
add (将文件添加到缓存区)& commit
git add *git add README
将缓存区内容添加到仓库中,-m 在命令行中提供提交注释
git commit -a -m "init project version"
git push命令 将本地分支,推送到远程主机
git push origin master
如果出现以下错误:
To https://git...git ![rejected] master -> master (fetch first) error: failed to push some refs to https://git...git hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes
使用命令进行解决
git push -f
status检查文件状态
git status
Ignore file 忽略指定文件 cat .gitignore 忽略文件 vim .gitignore 添加忽略的文件 diff git diff git diff --staged git diff --cached
查看已缓存的改动
git reset HEAD 用于取消已缓存的内容
git reset HEAD -- hello.jsp
git rm 将文件从缓存区和你的硬盘中(工作目录)删除
git rm hello.jsp
git mv 重命名磁盘上的文件 与 git rm --cached 命令的操作一样的效果
git fetch是从远程获取最新版本到本地
git fetch origin master git log -p master origin/master git merge origin/master
git pull 从远程获取最新版本并merge到本地
git pull origin master