顯示具有 電腦資訊-版本控制-svn 標籤的文章。 顯示所有文章
顯示具有 電腦資訊-版本控制-svn 標籤的文章。 顯示所有文章

2014/11/03

送交(commit) git log 到svn repository



最近迷上了git,所以基本上只要修改或建立新的專案我都是建立git的repository

不過公司還是使用svn當作repository

那如果我想要把我在git上的commit log保留並且commit到svn那該怎麼辦呢?

當初從svn轉到git有用到一個套件"git-svn"

這次也是利用它來達成我的目標:

將git的log commit到svn上

首先 安裝它

環境:CentOS 5.9

```
yum install git-svn
```

利用git-svn 抓取svn source tree下來

```
git svn clone svn://moa.tw/my/svn/repository/more/folder/is/working ./svn2git
```

將原先存在的git repository新增為svn2git底下名為source的remote

```
cd svn2git/
git remote add -f source /moa/tw/git/repo/project
```

重新間接基準點到git-svn

```
git rebase --onto remotes/git-svn --root source/master
```

途中也許有衝突發生

```
Auto-merging view/base2.tmpl.html
CONFLICT (content): Merge conflict in view/base2.tmpl.html
Auto-merging view/base.tmpl.html
CONFLICT (content): Merge conflict in view/base.tmpl.html
Failed to merge in the changes.
```

修正後繼續即可

```
git add view/base2.tmpl.html
git add view/base.tmpl.html
git rebase --continue
```

之後就會看到一堆類似下面的訊息,也就是正在一筆一筆轉換

```
Applying: xxxxxxxxxxxxxxxxx
Applying: yyyyyyyyyyyyyyyyy
```

跑完之後執行

```
git svn dcommit
```

就會把log一併commit到svn repository了

接下來該探討的就是:

我是否可以繼續用git commit/push到git的repo,但是我想要commit回svn時,隨時都可以commit,而不怕source衝突




參考連結:
http://goodliffe.blogspot.tw/2011/08/pushing-git-repository-into-existing.html

2014/10/03

如何做 “git export” (像 “svn export”)?



完成一個版本後想要發行

如果用git clone的話又會產生.git資料夾

以下提供如何做到像svn export一樣的功能

利用git archive
```
$ git archive -h
usage: git archive [options] <tree-ish> [<path>...]
or: git archive --list
or: git archive --remote <repo> [--exec <cmd>] [options] <tree-ish> [<path>...]
or: git archive --remote <repo> [--exec <cmd>] --list

--format <fmt> archive format
--prefix <prefix> prepend prefix to each pathname in the archive
-o, --output <file> write the archive to this file
--worktree-attributes
read .gitattributes in working directory
-v, --verbose report archived files on stderr
-0 store only
-1 compress faster
-9 compress better

-l, --list list supported archive formats

--remote <repo> retrieve the archive from remote repository <repo>
--exec <cmd> path to the remote git-upload-archive command
```

使用方法1:
倒出master到某個資料夾

```
git archive master | tar -x -C /somewhere/else
```


使用方法2:
倒出master時加入參數直接打包壓縮
```
git archive --format tar.gz --output /full/path/to/zipfile.tgz master
```

2014/10/01

轉移 svn 到 git



最近公司開始導入 git

我也開始學了一下~ 覺得 git 實在很好用

所以要把自己的 svn server 改成 git

以下教學如何把 svn 移植到git

首先先將 svn 中原有使用者資訊給列出

```shell
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > ~/authors-transform.txt
```

再來用灌 git-svn 並執行:
```shell
git svn clone "你的 svn repo" --no-metadata -A ~/authors-transform.txt --no-minimize-url ~/temp
```

這樣~/temp就會是你的 repo 了,如果原先 repo 很雜亂,多個專案都使用同一個的話也沒問題。

再來把git專案push到git server上

```shell
git remote add origin git@bitbucket.org:yours.git
git push -u origin --all
```

完成

2015/02/03 補充

在轉換的 svn 中,空的資料夾會遺失
必須加上 --preserve-empty-dirs

```shell
git svn clone "你的 svn repo" --no-metadata --preserve-empty-dirs -A ~/authors-transform.txt --no-minimize-url ~/temp
```
官網說明:
--preserve-empty-dirs
Create a placeholder file in the local Git repository for each empty directory fetched from Subversion. This includes directories that become empty by removing all entries in the Subversion repository (but not the directory itself). The placeholder files are also tracked and removed when no longer necessary.

--placeholder-filename=<filename>
Set the name of placeholder files created by --preserve-empty-dirs. Default: ".gitignore"


2016/01/07 補充

若只想 clone 部分範圍的 commit 可已加上 -r "開始版號":"結束版號"

```shell
git svn clone -r 100:200 "你的 svn repo" --no-metadata --preserve-empty-dirs -A ~/authors-transform.txt --no-minimize-url ~/temp
```

2014/06/16

SVN 備份與還原

備份:

```
svnadmin dump /your/repo > repo.dump
```

搭配gz壓縮
```
svnadmin dump /your/repo | gz -9 repo.dump.gz
```

還原:
```
svnadmin load /your/repo/dest < repo.dump
```