Git是目前世界上最先进的分布式版本控制系统(没有之一)。
本例使用的托管平台 码云网址链接
windows 下的管理软件 git
// https://git.oschina.net/huanuo/do.git 创建在码云的项目
$ git clone https://git.oschina.net/huanuo/do.git
Cloning into 'do'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git config --global user.email "[email protected]"
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git config --global user.name "argus.deng"
$ git config -l
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
rebase.autosquash=true
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.required=true
credential.helper=manager
user.emil=argus.deng@nokia,com
user.name=dengerhuan
[email protected]
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
remote.origin.url=https://git.oschina.net/huanuo/doweb.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
// 创建新的文件 newfile.txt 然后查看当前的额文件状态
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add ..." to include in what will be committed)
newfile.txt
$ git add newfile.txt // 将newfile.txt 添加到缓存区域
$ git commit -m "addnewfile" // 将缓存区域的文件 提交到仓库
[master 1210b9b] addnewfile
1 file changed, 1 insertion(+)
create mode 100644 newfile.txt
这样就完成了一个提交
git log 查看历史记录
git log -p 显示详细更改信息,
git log --pretty=oneline 显示简略信息
git log --pretty=oneline --graph 显示项目分支合并图。
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git log
commit ba461623c134d4734ec9804896a582fb2a63b9bd
Author: Deng argus
Date: Fri Apr 7 17:17:17 2017 +0800
add new file
commit e55ebbd9d4ea4b88134c66367dd0b52131f9b2d2
Author: 夸夸夸夸 <[email protected]>
Date: Fri Apr 7 16:35:12 2017 +0800
// 查看简略信息
$ git log --pretty=oneline
ba461623c134d4734ec9804896a582fb2a63b9bd add new file //每一条历史记录使用惟一的哈希码标注
e55ebbd9d4ea4b88134c66367dd0b52131f9b2d2 Initial commit
git checkout
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do ((ba46162...))
$ git checkout e55e
Previous HEAD position was ba46162... add new file
HEAD is now at e55ebbd... Initial commit
git 中的分支就是一个可移动指针,指向了某个历史记录。 默认的分支名是 master 。每次提交后, master 都会指向你刚才的提交记录。
git branch
git checkout -b
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git branch newbranch
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git checkout newbranch
Switched to branch 'newbranch'
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (newbranch)
$ git checkout -b anobranch
Switched to a new branch 'anobranch'
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (anobranch)
$
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (anobranch)
$ touch hellobranch.txt
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (anobranch)
$ ls
hellobranch.txt newfile.txt README.md
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (anobranch)
$ vim hellobranch.txt
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (anobranch)
$ git add hellobranch.txt
warning: LF will be replaced by CRLF in hellobranch.txt.
The file will have its original line endings in your working directory.
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (anobranch)
$ git commit -m "add hello branch"
[anobranch 14641f3] add hello branch
1 file changed, 1 insertion(+)
create mode 100644 hellobranch.txt
git merge hotfix
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (anobranch)
$ git checkout master // 切换到主分支
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git merge anobranch // 合并分支
Updating ba46162..14641f3
Fast-forward
hellobranch.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 hellobranch.txt
git branch -d branchname
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git branch -d anobranch
Deleted branch anobranch (was 14641f3).
git remote add
git remote show [remote-name] 查看某个远程仓库信息
git remote rename [old-name] [new-name] 重命名远程仓库
git remote rm [remote-name] 删除远程仓库
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git remote
origin
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git remote add oam https://git.oschina.net/huanuo/oam.git
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git remote
oam
origin
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git remote show oam
* remote oam
Fetch URL: https://git.oschina.net/huanuo/oam.git
Push URL: https://git.oschina.net/huanuo/oam.git
HEAD branch: master
Remote branch:
master new (next fetch will store in remotes/oam)
Local ref configured for 'git push':
master pushes to master (local out of date)
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git remote rename oam oamnewname
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git remote
oamnewname
origin
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git remote rm oamnewname
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git remote
origin
$ git push origin master
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git push origin master
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 520 bytes | 0 bytes/s, done.
Total 6 (delta 1), reused 0 (delta 0)
To https://git.oschina.net/huanuo/do.git
e55ebbd..14641f3 master -> master
git fetch
git pull
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git pull
Already up-to-date.
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/do (master)
$ git fetch
git push remotename --delete branchname
fan@DESKTOP-1OGO4V1 MINGW64 ~/Desktop/gti/test/do (master)
$ git push origin --delete newbranch
To https://git.oschina.net/huanuo/do.git
- [deleted] newbranch