程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> Git分布式版本控制教程,git教程

Git分布式版本控制教程,git教程

編輯:JAVA綜合教程

Git分布式版本控制教程,git教程


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 install
Solaris 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 "[email protected]"


查看配置信息

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

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved