Gerrit/TortoiseGit チュートリアル
このチュートリアルは、Windows ユーザーが Gerrit および git にソースコードを提供する際に役立つ場合があります。
ソフトウェアのインストール
- TortoiseGit と言語パッケージをダウンロードしてインストールします
- Git for Windows をダウンロードしてインストールします
- おすすめの「Windows Explorer integration – Simple context menus entries: "Git Bash here"」を選択します。
- デスクトップとクイック起動の「追加アイコン」を選択するかどうかは任意です
- 「Git GUI here」を選択することは任意ですが、ここではグラフィカル ユーザー インターフェイスとして TortoiseGit を使用します。
一方、その GUI を使用すると、必要に応じてローカルリポジトリの圧縮クリーンアップを迅速にしてくれます。 - 「Advances context menu (git-cheetah plugin)」を選択しないでください (古いリリースのみで利用可能)。
- *.git と *.sh のファイル関連付けは保持してください
- すべてのコンソール ウィンドウで TrueType フォントを使用するかどうかは利用者の判断です
- Keep the default
Start Menu Folder - 次のステップでは「Run Git from Windows Command Prompt」を選択します。そうしないと一部のスクリプトが実行されない場合があります。
- 行末変換については3番目の項目「Checkout as-is, commit as-is」を選択します
- おすすめの「Windows Explorer integration – Simple context menus entries: "Git Bash here"」を選択します。
Setting up environment
Create and publish your SSH-Key
- Start puTTYgen in the Start menu or in
C:\Program Files\TortoiseGit\bin\puttygen.exe, create a new SSH key and save the private key it in a .ppk file; also save the public key. - Login to gerrit:, use your labs username and password
- Go to
Settings > SSH Public Keysand add your public key - Go to
Settings > Identitiesand verify your email address and account (identity)
Clone your working copy
- Right-click in Windows Explorer, and select "Git clone" to clone a repository to the given directory. Use the URL from Gerrit repository e.g.
https://gerrit.wikimedia.org/r/pywikibot/corefor the pywikibot core. - Select the
recursiveswitch. - If "Load Putty Key" is on, deselect that button as we cover that in the next step.
Setting up TortoiseGit
- Right-click on your repository and open
TortoiseGit > Settings - Choose
Git > Remoteand select "origin" remote server. Verify the URL and select your private puTTYkey .ppk file if not done previously. - Choose
Git(orGit > Config) and verify that your Name and Email of the User Info is the same as your Gerrit account. - Click on
Edit global .gitconfigand again verify your name and email to be the same as in Gerrit. - Choose
General > Set Extend Menu Itemand deselectBrowse References
Git設定
Gerrit is used for the review workflow and Git has to be instructed to push changes to Gerrit, instead of to the official Git repository. There are two ways to do it:
TortoiseGitの使用
- Again, re-open
TortoiseGit > Settingsand chooseGit(orGit > Config) - Click on Edit global .gitconfig button and add the following sections:
[url "ssh://<username>@gerrit.wikimedia.org:29418"]
insteadOf = https://gerrit.wikimedia.org/r/
[branch]
autosetuprebase = remote
git bashの使用
- Right-click on your repository and start
Git Bash Here - Type the following lines:
git config --global url."ssh://<username>@gerrit.wikimedia.org:29418".insteadOf "https://gerrit.wikimedia.org/r/"git config --global branch.autosetuprebase remote.
Install commit-msg hook
- Download the commit-msg hook script from the repo and install it into the
<project name>/.git/hooksfolder using Save As...
注: .gitis a hidden folder.- 関連項目: Gerrit/Alternatives to git-review – for other variants to install the script.
Working with repository
All needed commands of TortoiseGit you'll find in the context menu by right-click on your local repository choosing TortoiseGit.
It is not necessary to have Gerrit/git-review installed.
View repository log
There are two ways to show the repository log:
- Use the
Show logcommand - Use Windows
Propertiesin the context menu. SelectGittab and choose Show log button.
Update your repository
For updating you local repository you may do it with the following steps:
- Stash your local changes with
Stash Savecommand. You may enter a comment or ignore it. Another way to save your local changes is to commit them to the local repository, which will explained later. Pull...changes from remote repository. KeepAutoLoad Putty Keychecked. You may checkLaunch Rebase after Fetchto start rebase or start it manually.- Rebase your repository to fast forward local master branch to its remote branch. Either use
Rebase...option or check the depending checkbox above. Then click Start (FastFwd) if needed and klick Done when you are finished or Abort. Stash popto apply your local changes to the working tree and remove the stash from the stack.
Update externals
- Use
Submodule Update...for it. This is needed e.g. for i18n messages.
新しいChangesetを作る
If you want change the code and push it to remote repository, do it by these steps:
- Select
Create Branchand enter a meaningfull branch name. Enable check boxSwitch to new branchand click OK. If you haven't enabled this check box you may use theSwitch/Checkout...command after that. Creating a new branch is also available from context menu inside repository log. - Make your changes on your local repository and test it.
- Commit you changeset to the local repository by
Git Commit -> <your local branch name>command; this command is part of the windows context menu not the TortoiseGit context submenu. - Add a descriptive commit message into the message field for your commit. Refer Gerrit/Commit message guidelines.
- Click
View Patch>>at the bottom of the dialog window to see the patch and verify the changes. - Enable the checkbox
Amend Last Commitif this change is a follow-up of an already commited patch of the same branch - Klick Commit
- Push... to submit your patch to the remote repository for peer review, otherwise press close
パッチの投稿
- Either use Push... of the commit dialog or use
Push...from context menu. Local:: Select you local branch to submit. Default is your actual branchRemote:typerefs/for/masterfor the destination. You may easily add a gerrit topic for your changeset by appending it separated by "%topic=", e.g.refs/for/master%topic=mytopic.- Press OK to submit your patch.
Download a patch for review
You may download a patch form another developers to your local repository to review it by following steps:
- First create a new local branch
- Choose
Fetch.... A new dialog window will be opened. - Select
Arbitrary URL. - Enter the repository URL there, e.g.
ssh://<username>@gerrit.wikimedia.org:29418/pywikibot/core - Enter the remote branch setting like
refs/changes/<index no>/<change no>/<PS no>e.g.refs/changes/32/9332/1, where<index no>are the last two digits of<change no><change no>is the gerrit change number<PS no>is patch set number of that change
- OK to fetch this patch set
- Choose
Git Bash herefrom windows context menu - type
git cherry-pick FETCH_HEADin the git window
Problems, issues and workarounds
Missing Change-Id in commit message
Install commit-msg hook first, see above.
Git Clone hangs
If Git Clone... hangs after "Resolving deltas" hits 100% and you are using PuTTY: Open up PuTTY, load Default Settings, and set "Chokes on PuTTY's SSH-2 'winadj' requests" to "On" under Connection->SSH->Bugs. Then select Session, select Default Settings, and Save.