バージョン管理システム

作成日 : 2013-11-71
最終更新日 :

バージョン管理システムとは

バージョン管理システムとは、コンピュータ上で作成、編集されるファイル、特にプログラムのソースコードの変更履歴を管理するためのシステムをいう。 エスペラントでは、versitena sistemo という。

バージョン管理システムの種類

SCCS

Source Code Control System の略。その名前の通り、 ソースコードを管理するシステムである。私が初めて使ったバージョン管理システムでもある。

RCS

Revision Control System の略。私が使ったバージョン管理システムの中では、 一番長きにわたって使っていた。その後のバージョン管理システムはクライアント・サーバ型になり、 ややこしいと感じてしまったため使わなくなった。

CVS

Concurrent Versions System の略。ソースコードを含めたテキストファイルを管理するシステム。 CVS 用のサーバを用意し、クライアントから操作する。

SubVersion

CVS の欠点を克服するために作られたのが SubVersion である。 2020 年現在も Apache SubVersion として更新が続けられている。 Unix のページにありながら、Windows で動く TortoiseSVN を使ってみることにした。

http://tortoisesvn.net/docs/nightly/TortoiseSVN_ja/tsvn-qs-guide.html に従い、上記フォルダをエクスプローラで右クリックし、TortoiseSVN → ここにリポジトリを作成… を選択する。ダイアログウィンドウが出てくるので、[フォルダ構造を作成]ボタンをクイックする。あとは [OK]。

そして、フォルダー内にプロジェクトをリポジトリに収める(インポートする)。収めたいフォルダを右クリックして、 TortoiseSVN → インポート... を実行する。このとき、インポートダイアログのウィンドウが表示される。 リポジトリが正しいことを確認し、インポートメッセ―ジを入力する。ここで、[OK] ボタンをクリックする。

リポジトリからプロジェクトを取り出すときはどうするか。新たなフォルダを作り、そこに取り出す、言い換えれば新しい作業コピーをとるようにする。 これをチェックアウトという。チェックアウトの方法は次の通りである。 新たなフォルダを右クリックし、TortoiseSVN →チェックアウト... を選択する。

Git

Git は分散型の管理ツールである。GitHub とあわせて使えばよい。

SourceTree

Git と合わせて使われるツールに SourceTree がある。 SourceTree をインストールしていろいろと操作をしていると、こんなエラーが出た。

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=manager-st push -v --tags origin master:master
Pushing to https://github.com/marinkyo/hejmpagxo
To https://github.com/marinkyo/hejmpagxo
 ! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to 'https://github.com/marinkyo/hejmpagxo'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
エラー: 'https://github.com/marinkyo/hejmpagxo' を参照しているファイルの push に失敗しました。
ヒント: 更新が失敗しました。理由はカレントブランチの tip がリモートの
ヒント: カウンターパートに隠れているから。再度ブッシュする前に、
ヒント: リモートのチェンジをまとめること (例:'git pull ...') 
ヒント: See the 'Note about fast-forwards' in 'git push --help' for details.

上記エラーは、プル (pull) をしたらなくなった。あたりまえか。

Git ふたたび

その後、知人のプロジェクトの手伝いでおっかなびっくり git と github を使っていた。 このプロジェクトも一段落し、git をしばらく使わなくなっていた。

その後、ふとしたことで Rust という言語を学んでみることにした。 すると、この Rust はプロジェクト作成と同時に、git を前提としたバージョン管理を強いるようなのだ。 というのも、

  $ cargo new --bin projectname

でプロジェクトを作ると、この projectname でディレクトリ(フォルダ)が作られると同時に、 そのプロジェクトに .git ディレクトリと .gitignore ファイルを自動的に作るのだ。

さて、この projectname というディレクトリには、 src というソースコードを置くサブディレクトリもできる。ここに main.rs というファイルができている。 この main.rs も git による管理ができるということだろうか。 git add main.rs の前後でステータスの変化を調べてみよう。

$ git status
ブランチ master

No commits yet
  
追跡されていないファイル:
  (use "git add <file>..." to include in what will be committed)
        .gitignore
        Cargo.lock
        Cargo.toml
        src/
  
nothing added to commit but untracked files present (use "git add" to track)
$ git add main.rs
$ git status
ブランチ master

No commits yet

コミット予定の変更点:
  (use "git rm --cached <file>..." to unstage)
        new file:   main.rs

追跡されていないファイル:
  (use "git add <file>..." to include in what will be committed)
        ../.gitignore
        ../Cargo.lock
        ../Cargo.toml

確かに変化している。では、コミットしてみよう。

(base) $ git commit -m "プログラミング Rust pp.17-19"

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <username@userPCname.localdomain>) not allowed

「貴様は何者か、名を名乗れ」と言われている。 このリポジトリだけでいいので、--global を省いて名乗ることにした。

$ git config user.name "MARUYAMA Satosi"
$ git commit -m "プログラミング Rust pp.17-19"
[master (root-commit) d07f30e] プログラミング Rust pp.17-19
 Committer: MARUYAMA Satosi <username@userPCname.localdomain>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 23 insertions(+)
 create mode 100644 src/main.rs
$ git status
ブランチ master
追跡されていないファイル:
  (use "git add <file>..." to include in what will be committed)
        ../.gitignore
        ../Cargo.lock
        ../Cargo.toml

nothing added to commit but untracked files present (use "git add" to track)
(base) $ git status
ブランチ master
追跡されていないファイル:
  (use "git add ..." to include in what will be committed)
        ../.gitignore
        ../Cargo.lock
        ../Cargo.toml

nothing added to commit but untracked files present (use "git add" to track)
$ git log
commit d07f30e40d9146ba9cd4a8d85c96506c2fa49687 (HEAD -> master)
Author: MARUYAMA Satosi <username@userPCname.localdomain>
Date:   Sat Oct 3 19:14:53 2020 +0900

    プログラミング Rust pp.17-19

リンク

まりんきょ学問所UNIX 手習い > バージョン管理システム


MARUYAMA Satosi