git and svn。
git
Git是分布式管理工具,因此没有真正的Server。
基本命令
- CREATE
Clone an existing repository
$ git clone ssh://user@domain.com/repo.git
Create a new local repository
$ git init
- LOCAL CHANGES
Changed files in your working directory
$ git status
Changes to tracked files
$ git diff
Add all current changes to the next commit
$ git add .
Add some changes in <file> to the next commit
$ git add -p <file>
Commit all local changes in tracked files
$ git commit -a
Commit previously staged changes
$ git commit
Change the last commit
Don‘t amend published commits!
$ git commit --amend
- COMMIT HISTORY
Show all commits, starting with newest
$ git log
Show changes over time for a specific file
$ git log -p <file>
Who changed what and when in <file>
$ git blame <file>
- BRANCHES & TAGS
List all existing branches
$ git branch -av
Switch HEAD branch
$ git checkout <branch>
Create a new branch based on your current HEAD
$ git branch <new-branch>
Create a new tracking branch based on a remote branch
$ git checkout --track <remote/branch>
Delete a local branch
$ git branch -d <branch>
Mark the current commit with a tag
$ git tag <tag-name>
- UPDATE & PUBLISH
List all currently configured remotes
$ git remote -v
Show information about a remote
$ git remote show <remote>
Add new remote repository, named <remote>
$ git remote add <shortname> <url>
Download all changes from <remote>, but don‘t integrate into HEAD
$ git fetch <remote>
Download changes and directly merge/integrate into HEAD
$ git pull <remote> <branch>
Publish local changes on a remote
$ git push <remote> <branch>
Delete a branch on the remote
$ git branch -dr <remote/branch>
Publish your tag s
$ git push --tags
- MERGE & REBASE
Merge <branch> into your current HEAD
$ git merge <branch>
Rebase your current HEAD onto <branch>
Don‘t rebase published commits!
$ git rebase <branch>
Abort a rebase
$ git rebase --abort
Continue a rebase after resolving conflicts
$ git rebase --continue
Use your configured merge tool to solve conflicts
$ git mergetool
Use your editor to manually solve conflicts and (after resolving) mark file as resolved
$ git add <resolved-file>
$ git rm <resolved-file>
- UNDO ```sh Discard all local changes in your working directory $ git reset –hard HEAD
Discard local changes in a specific file
$ git checkout HEAD
Revert a commit (by producing a new commit with contrary changes)
$ git revert
Reset your HEAD pointer to a previous commit
…and discard all changes since then
$ git reset –hard
…and preserve all changes as unstaged changes
$ git reset
…and preserve uncommitted local changes
$ git reset –keep
### 配置
- 设置用户名和邮件地址
$ git config –global user.name “jason” $ git config –global user.email jason@example.com
### Linux Gitolite服务器搭建
- 安装软件
```sh
Server端: sudo apt-get install git
Client端: Git-2.14.2-64-bit.exe、TortoiseGit-2.5.0.0-64bit.msi
- Server端配置及生成SSH KEY
$ git config -l
$ git config --global user.name "jason"
$ git config --global user.email "jason@example.com"
$ ssh-keygen -t rsa -C "jason@example.com"
为了区分,将其重命名:
$ mv .ssh/id_rsa.pub .ssh/jason.pub
- Server端创建Git用户
$ sudo adduser git
$ sudo passwd git
$ vi /etc/sudoers
# User privilege specification
git ALL=(ALL:ALL) ALL
$ su - git
- Server端安装gitolite
git clone https://github.com/sitaramc/gitolite.git
mkdir -p ${HOME}/bin
${HOME}/gitolite/install -to ${HOME}/bin
- Server端设置SSH public key
${HOME}/bin/gitolite setup -pk .ssh/jason.pub
- 安装SSH
sudo apt-get install openssh-server
- Server端:
git clone git@192.168.72.129:gitolite-admin.git
conf keydir
-
Client端: 生成SSH KEY, 为了便于区分将其重命名jason.pub,拷贝到Server端。
-
Server端:
vim gitolite-admin/conf/gitolite.conf
repo gitolite-admin
RW+ = jason
cp jason.pub gitolite-admin/keydir/jason.pub
cd gitolite-admin
git add .
git commit -am "add user jason"
git push origin master
- 新建项目
git init --bare repositories/project_name.git
vim /home/git/projects/gitolite-admin/conf/gitolite.conf
repo project_name
RW+ = jason
git commit -am "add repo"
git push origin master
- Client:
git clone git@192.168.72.129:gitolite-admin.git
- 使用TortoiseGit生成ppk秘钥
git的rsa秘钥不适用于TortoiseGit。
PuTTY Key Generator -> Generate
copy public key -> Server端
modify conf, keydir并提交
github
- push时总是弹框输入密码,解决方法
推送需要密码是因为开始关联本地git库和github时用的关联方式为HTTP方式,而不是ssh密钥方式,所有需要更改关联方式。
编辑D:\Personal\Projects\github\xxx.github.io\.git\config
- url = https://github.com/xxx/xxx.github.io.git
+ url = git@github.com:xxx/xxx.github.io.git
Windows下Git多账号配置,同一电脑多个ssh-key的管理
~/.ssh/config
# 配置github.com
Host github.com
HostName github.com
IdentityFile C:\\Users\\jason\\.ssh\\jason_github
PreferredAuthentications publickey
User jason
# 配置147.98.244.22
Host 147.98.244.22
HostName 147.98.244.22
IdentityFile C:\\Users\\jason\\.ssh\\jason
PreferredAuthentications publickey
User jason
svn
Linux环境中搭建SVN服务器
-
安装svn 可以通过在线安装或者通过源码包来进行编译安装。
- 创建版本库
svnadmin create /opt/repos
执行该命令之后,如果repos不存在将会首先自动在相应的路径中创建repos文件夹,同时会在repos中生成一些文件。
- 修改版本库配置文件
进入/opt/repos/conf目录中,编辑svnserve.conf,去掉如下几行开头的#注释,并且作如下修改:
anon-access = none #禁止匿名用户读写操作
auth-access = write #使授权用户有写的权限
password-db = passwd
- 设置svn账号密码 ```sh vim /opt/repos/conf/passwd
在[users]块中设置账号和密码,格式:用户名 = 密码 例如: [users] jason = 123 Peter = 321
- 配置权限
```sh
vi /opt/repos/conf/passwd/authz
在文件末尾添加如下内容:
[/]
jason = rw
Peter = r
实现的效果是用户jason对版本库根目录具备读写权限,而Peter只具备读权限。
- 启动svn服务
svnserve -d -r /opt/repos
其中,-d选项表示svnserve 将以守护进程的方式运行,-r选项用来指定版本库的根目录,这样用户就可以使用相对路径访问。
- 导入项目工程文件
在本地创建项目工程文件:
mkdir -pv /tmp/GameProject/{branches,tags,trunk}
在本地通过file:///方式导入至仓库中:
svn import /tmp/GameProject file:///opt/repos/GameProject -m "initial import game project"
- 检出项目
方式一:通过命令行。
svn checkout svn://192.168.23.200/GameProject
方式二:通过TortoiseSVN可视化工具。