Saturday, February 1, 2014

git本地和公共仓库配置

基于公共仓库创建版本管理:
##建立远程公共仓库
cd /tmp/
mkdir gitrepo 
cd gitrepo/ 
git init 
##创建一个空文件,从而产生一个branch
touch a.txt 
git add a.txt  
git commit -m "a.txt" a.txt 
##根据远程公共仓库,在home目录下产生一个本地仓库
cd ~ 
git clone alex@localhost:/tmp/gitrepo gitrepo 
##添加一个新的文件,并上传到远程仓库
cd gitrepo/ 
echo "helloworld" > fuzzy.txt 
git add fuzzy.txt  
git commit -m "helloworld" fuzzy.txt  
git push origin 
##创建另一个本地仓库
cd /tmp/ 
mkdir gitn 
cd gitn 
git clone alex@localhost:/tmp/gitrepo 
##添加一个新的文件,并上传到远程仓库
cd gitrepo/ 
mkdir new 
touch new/new.txt 
git add new/new.txt  
git commit -m "new.txt" new/new.txt  
git push  
##更新原home下的本地仓库
cd ~/gitrepo/ 
git pull
基于本地仓库创建公共仓库的版本管理:
##建立本地仓库
cd ~/
git init gitrepo 
cd gitrepo/ 
##创建一个空文件,从而产生一个branch
touch a.txt 
git commit -m "a.txt" a.txt  
git add a.txt  
git commit -m "a.txt" a.txt  
##使用本地仓库,在服务端创建公共仓库
cd /tmp/ 
mkdir gitrepo 
cd gitrepo/ 
git clone –bare alex@localhost:/home/alex/gitrepo public.git 
##在本地仓库,添加服务端的公共仓库路径
cd ~/gitrepo/ 
git remote add origin alex@localhost:/tmp/gitrepo/public 
######################################
##执行上面的语句后.git/config文件内容如下:
######################################
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = alex@localhost:/tmp/gitrepo/public
    fetch = +refs/heads/*:refs/remotes/origin/*
gvim .git/config  
######################################
##需要在.git/config中添加branch的内容
##不知道如何用命令添加,修改文档添加可行
######################################
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = alex@localhost:/tmp/gitrepo/public
    fetch = +refs/heads/*:refs/remotes/origin/*
    remote = origin
    merge = refs/heads/master
##更新远程仓库
git remote update 
##添加一个新的文件,并上传到远程仓库
echo "helloworld" > fuzzy.txt 
git add fuzzy.txt  
git commit -m "helloworld" fuzzy.txt  
git push 
##创建另一个本地仓库
cd /tmp/ 
mkdir gitn 
cd gitn 
git clone alex@localhost:/tmp/gitrepo/public.git 
cd public/ 
##添加一个新的文件,并上传到远程仓库
mkdir new 
touch new/new.txt 
git add new/new.txt  
git commit -m "new.txt" new/new.txt  
git push 
##更新原home下的本地仓库
cd ~/gitrepo/ 
git pull
git配置文件设置:
1)系统全局配置文件:
/etc/gitconifg
系统上默认没找到这个文件,这边就不展开了
2)用户全局配置文件:
~/.gitconfig
#######配置文件样例######
[user]
name = Alex Hsu
email = alexu2595@gmail.com
[core]
editor = gvim
[merge]
tool = gvimdiff
[color]
diff = auto
status = auto
branch = auto
[alias]
co = checkout
###################
可以通过修改~/.gitconfig配置文件修改相应的配置,或者使用下面的命令进行修改:
git config –global alias.co checkout
3)每个git仓库的配置文件:
git_reposity/[name].git/config
#######配置文件样例######
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[user]
name = Alex Hsu
[alias]
co = checkout
###################
可以通过修改git_reposity/[name].git/config配置文件修改相应的配置,或者使用下面的命令进行修改:
git config  alias.co checkout

No comments:

Post a Comment