「Git」の版間の差分
(他言語へのリンクを追加) |
|||
| (5人の利用者による、間の39版が非表示) | |||
| 1行目: | 1行目: | ||
[[Category:バージョン管理システム]] |
[[Category:バージョン管理システム]] |
||
| + | [[Category:コマンド]] |
||
| + | [[Category:OpenPGP]] |
||
| + | [[de:Git]] |
||
[[en:Git]] |
[[en:Git]] |
||
| − | [[ |
+ | [[es:Git]] |
| + | [[ru:Git]] |
||
| + | [[zh-hans:Git]] |
||
{{Related articles start}} |
{{Related articles start}} |
||
| − | {{ |
+ | {{Related|Bisecting bugs with Git}} |
| + | {{Related|Concurrent Versions System}} |
||
| − | {{Related4|Gitweb}} |
||
| + | {{Related|Git サーバー}} |
||
| − | {{Related4|Cgit}} |
||
| + | {{Related|Gitweb}} |
||
| − | {{Related3|HTTP tunneling#Tunneling Git|HTTP トンネリング#Git のトンネリング}} |
||
| + | {{Related|HTTP トンネリング#Git のトンネリング}} |
||
{{Related|Subversion}} |
{{Related|Subversion}} |
||
| + | {{Related|VCS パッケージガイドライン}} |
||
| − | {{Related4|Concurrent Versions System}} |
||
{{Related articles end}} |
{{Related articles end}} |
||
| 15行目: | 21行目: | ||
== インストール == |
== インストール == |
||
| − | {{Pkg|git}} パッケージを[[インストール]]してください。 |
+ | {{Pkg|git}} パッケージを [[インストール]] して下さい。開発版の場合は、{{AUR|git-git}} パッケージをインストールします。''git svn''、''git gui''、''gitk'' などのツールを使用する場合は、オプションの依存関係を確認してください。 |
| + | === グラフィカルフロントエンド === |
||
| − | Git の補助ツールを使いたい場合は、必要に応じて任意の依存パッケージもインストールしてください。GUI ツール (例: ''gitk'' や ''git gui'') は {{Pkg|tk}} パッケージを必要とし、インストールしていない場合エラーで起動できません: |
||
| + | 参照 [https://git-scm.com/download/gui/linux git GUI クライアント] |
||
| − | /usr/bin/gitk: line 3: exec: wish: not found. |
||
| + | * {{App|Giggle|Git の GTK フロントエンド|https://wiki.gnome.org/Apps/giggle/|{{Pkg|giggle}}}} |
||
| − | また、GUI ツールは {{pkg|gsfonts}} を必要とし、インストールしていない場合セグメンテーション違反でクラッシュします。 |
||
| + | * {{App|GitAhead|組み込みの Merge Tool を含むグラフィカル Git クライアント|https://gitahead.github.io/gitahead.com/|{{AUR|gitahead}}}} |
||
| − | |||
| + | * {{App|Git Cola|Python で書かれた Git 用の洗練された強力なグラフィカル ユーザーインターフェイス|https://git-cola.github.io/|{{AUR|git-cola}}}} |
||
| − | Git SVN ブリッジ (''git svn'') を使いたい場合は {{pkg|perl-term-readkey}} も必要です。インストールしていない場合、次のエラーが表示されます: |
||
| + | * {{App|Git Extensions|コマンドラインを使用せずに Git を制御できる Git のグラフィカルユーザーインターフェイス|https://gitextensions.github.io/|{{AUR|gitextensions}}}} |
||
| − | |||
| + | * {{App|gitg|Git リポジトリを表示するための GNOME GUI クライアント|https://wiki.gnome.org/Apps/Gitg|{{Pkg|gitg}}}} |
||
| − | Can't locate Term/ReadKey.pm in @INC (you may need to install the Term::ReadKey module) |
||
| + | * {{App|git-gui|Git への Tcl/Tk ベースの移植可能なグラフィカルインターフェイス|https://git-scm.com/docs/git-gui|{{Pkg|git}} + {{Pkg|tk}}}} |
||
| + | :{{Note|''git-gui'' でスペル チェックを有効にするには、{{ic|LC_MESSAGES}} [[環境変数]] に対応する辞書と共に aspell が必要です。{{Bug|28181}} そして [https://wiki.archlinux.org/title/Language_checking#Spell_checkers aspell] の記事を参照。}} |
||
| + | * {{App|GitHub Desktop|GitHub チームによって構築された Electron ベースのグラフィカルユーザーインターフェイス|https://github.com/desktop/desktop|{{AUR|github-desktop}} {{AUR|github-desktop-bin}}}} |
||
| + | * {{App|gitk|Tcl/Tk ベースの Git リポジトリブラウザ|https://git-scm.com/docs/gitk|{{Pkg|git}} + {{Pkg|tk}}}} |
||
| + | * {{App|Guitar|Git GUI クライアント|https://github.com/soramimi/Guitar|{{AUR|guitar}}}} |
||
| + | * {{App|lazygit|git コマンド用のシンプルなターミナル UI|https://github.com/jesseduffield/lazygit|{{Pkg|lazygit}}}} |
||
| + | * {{App|QGit|リビジョン履歴を参照し、パッチの内容と変更されたファイルを表示し、さまざまな開発ブランチをグラフィカルにたどる Git GUI ビューア|https://github.com/tibirna/qgit|{{Pkg|qgit}}}} |
||
| + | * {{App|[[Wikipedia:RabbitVCS|RabbitVCS]]|使用しているバージョン管理システムへのシンプルで直接的なアクセスを提供するために作成されたグラフィカルツールのセット|http://rabbitvcs.org/|{{AUR|rabbitvcs}}}} |
||
| + | * {{App|Sublime Merge|Sublime Text のメーカーによる Git クライアント|https://www.sublimemerge.com/|{{AUR|sublime-merge}}}} |
||
| + | * {{App|Tig|git 用の ncurses ベースのテキストモードインターフェイス|https://jonas.github.io/tig/|{{Pkg|tig}}}} |
||
| + | * {{App|ungit|git の汎用性を犠牲にすることなく、git に使いやすさをもたらします|https://github.com/FredrikNoren/ungit|{{AUR|nodejs-ungit}}}} |
||
== 基本設定 == |
== 基本設定 == |
||
| 33行目: | 50行目: | ||
$ git config --global user.name "''John Doe''" |
$ git config --global user.name "''John Doe''" |
||
$ git config --global user.email "''johndoe@foobar.com''" |
$ git config --global user.email "''johndoe@foobar.com''" |
||
| + | |||
| + | こちらも参照 [https://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup Getting Started - First-Time Git Setup] |
||
他の設定については [[#高度な設定]] を見て下さい。 |
他の設定については [[#高度な設定]] を見て下さい。 |
||
| − | == |
+ | == 使い方 == |
| + | Gitリポジトリは、リビジョン履歴やその他のメタデータを保持する {{ic|.git}} ディレクトリ内に含まれています。リポジトリによって追跡されるディレクトリは、デフォルトでは親ディレクトリであり、作業ディレクトリ(working directory)と呼ばれます。作業ツリー(working tree)内の変更は、リポジトリに記録(コミット)する前にステージングする必要があります。また、Gitを使用すると、以前にコミットされた作業ツリーのファイルを復元することもできます。 |
||
| − | このチュートリアルでは Git によるプロジェクトの基本的な分散バージョン管理について説明します。典型的な Git のワークフローは以下の通りです: |
||
| + | [https://git-scm.com/book/en/Getting-Started-Git-Basics Getting Started - Git Basics] を参照してください。 |
||
| − | # 新しいプロジェクトを作成、またはリモートのプロジェクトを複製する。 |
||
| − | # ブランチを作成して変更を加え、変更をコミットする。 |
||
| − | # コミットを統合して上手くまとめて分かりやすくする。 |
||
| − | # メインのブランチにコミットをマージする。 |
||
| − | # (任意) 変更をリモートサーバーにプッシュする。 |
||
| − | === |
+ | === Git リポジトリの取得 === |
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e5%9f%ba%e6%9c%ac-Git-%e3%83%aa%e3%83%9d%e3%82%b8%e3%83%88%e3%83%aa%e3%81%ae%e5%8f%96%e5%be%97 Git リポジトリの取得 - Git の基本] を参照してください |
||
| − | ==== 準備 ==== |
||
| + | === 変更の記録 === |
||
| − | '''Initialize''' a new repository: |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e5%9f%ba%e6%9c%ac-%e5%a4%89%e6%9b%b4%e5%86%85%e5%ae%b9%e3%81%ae%e3%83%aa%e3%83%9d%e3%82%b8%e3%83%88%e3%83%aa%e3%81%b8%e3%81%ae%e8%a8%98%e9%8c%b2 変更内容のリポジトリへの記録 - Git の基本] を参照してください |
||
| − | $ git init |
||
| + | === コミット履歴の閲覧 === |
||
| − | To record the changes to the repository, they must first be added to the ''index'', or ''staging area'', with an operation often also referred to as ''staging''. To '''add files''': |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e5%9f%ba%e6%9c%ac-%e3%82%b3%e3%83%9f%e3%83%83%e3%83%88%e5%b1%a5%e6%ad%b4%e3%81%ae%e9%96%b2%e8%a6%a7 コミット履歴の閲覧 - Git の基本] を参照してください |
||
| − | $ git add ''file1'' ''file2'' |
||
| + | === 元に戻す === |
||
| − | '''Add all''' files: |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e5%9f%ba%e6%9c%ac-%e4%bd%9c%e6%a5%ad%e3%81%ae%e3%82%84%e3%82%8a%e7%9b%b4%e3%81%97 作業のやり直し - Git の基本] を参照してください |
||
| − | $ git add . |
||
| + | === リモートの操作 === |
||
| − | {{Tip|To '''ignore''' some files from, e.g. {{ic|git add .}}, create a {{ic|.gitignore}} file (or files): |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e5%9f%ba%e6%9c%ac-%e3%83%aa%e3%83%a2%e3%83%bc%e3%83%88%e3%81%a7%e3%81%ae%e4%bd%9c%e6%a5%ad リモートでの作業 - Git の基本] を参照してください |
||
| − | {{hc|.gitignore| |
||
| − | # File I'll likely delete |
||
| − | test-script |
||
| + | === ブランチ === |
||
| − | # Ignore all .html files, except 'important.html' |
||
| − | *.html |
||
| − | !important.html |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%83%96%e3%83%a9%e3%83%b3%e3%83%81%e6%a9%9f%e8%83%bd-%e3%83%96%e3%83%a9%e3%83%b3%e3%83%81%e3%81%a8%e3%81%af ブランチの概要 - Git のブランチ機能] を参照してください |
||
| − | # Ignore all files recursively in 'DoNotInclude' |
||
| − | DoNotInclude/** |
||
| − | }} |
||
| + | ==== 基本的なブランチとマージ ==== |
||
| − | See [http://git-scm.com/docs/gitignore gitignore(5)] for details. |
||
| − | }} |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%83%96%e3%83%a9%e3%83%b3%e3%83%81%e6%a9%9f%e8%83%bd-%e3%83%96%e3%83%a9%e3%83%b3%e3%83%81%e3%81%a8%e3%83%9e%e3%83%bc%e3%82%b8%e3%81%ae%e5%9f%ba%e6%9c%ac ブランチとマージの基本 - Git のブランチ機能] を参照してください |
||
| − | '''Remove''' a file from staging ({{ic|--cached}} preserves the actual file(s)): |
||
| + | ==== ブランチ管理 ==== |
||
| − | $ git rm ''(--cached)'' ''file'' |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%83%96%e3%83%a9%e3%83%b3%e3%83%81%e6%a9%9f%e8%83%bd-%e3%83%96%e3%83%a9%e3%83%b3%e3%83%81%e3%81%ae%e7%ae%a1%e7%90%86 ブランチ管理 - Git のブランチ機能] を参照してください |
||
| − | '''Remove all''' files: |
||
| + | ==== ブランチでの作業の流れ ==== |
||
| − | $ git reset HEAD -- . |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%83%96%e3%83%a9%e3%83%b3%e3%83%81%e6%a9%9f%e8%83%bd-%e3%83%96%e3%83%a9%e3%83%b3%e3%83%81%e3%81%a7%e3%81%ae%e4%bd%9c%e6%a5%ad%e3%81%ae%e6%b5%81%e3%82%8c ブランチでの作業の流れ - Git のブランチ機能] を参照してください |
||
| − | Or: |
||
| + | ==== リモートブランチ ==== |
||
| − | $ git rm --cached -r . |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%83%96%e3%83%a9%e3%83%b3%e3%83%81%e6%a9%9f%e8%83%bd-%e3%83%aa%e3%83%a2%e3%83%bc%e3%83%88%e3%83%96%e3%83%a9%e3%83%b3%e3%83%81 リモートブランチ - Git のブランチ機能] を参照してください |
||
| − | '''Rename''' a file: |
||
| + | ==== リベース ==== |
||
| − | $ git mv ''file1'' ''file2'' |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%83%96%e3%83%a9%e3%83%b3%e3%83%81%e6%a9%9f%e8%83%bd-%e3%83%aa%e3%83%99%e3%83%bc%e3%82%b9 リベース - Git のブランチ機能] を参照してください |
||
| − | '''List''' files: |
||
| + | === コラボレーション === |
||
| − | $ git ls-files |
||
| − | ==== |
+ | ==== 分散ワークフロー ==== |
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%a7%e3%81%ae%e5%88%86%e6%95%a3%e4%bd%9c%e6%a5%ad-%e5%88%86%e6%95%a3%e4%bd%9c%e6%a5%ad%e3%81%ae%e6%b5%81%e3%82%8c 分散作業の流れ - Git での分散作業] を参照してください |
||
| − | Once the content to be recorded is ''staged'', '''commit''' them with: |
||
| + | ==== プロジェクトへの貢献==== |
||
| − | $ git commit -m "''First commit.''" |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%a7%e3%81%ae%e5%88%86%e6%95%a3%e4%bd%9c%e6%a5%ad-%e3%83%97%e3%83%ad%e3%82%b8%e3%82%a7%e3%82%af%e3%83%88%e3%81%b8%e3%81%ae%e8%b2%a2%e7%8c%ae プロジェクトへの貢献 - Git での分散作業] を参照してください |
||
| − | The {{ic|-m}}, {{ic|--message}} option is for a short message: if omitted, the preset editor will be spawned to allow entering a longer message. |
||
| + | ==== プロジェクトの運営 ==== |
||
| − | {{Tip| |
||
| − | * Always commit small changes frequently and with meaningful messages. |
||
| − | * To '''add''' all the modified files to the index, '''and commit''' them in a single command ({{ic|-a}} stands for {{ic|--all}}): |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%a7%e3%81%ae%e5%88%86%e6%95%a3%e4%bd%9c%e6%a5%ad-%e3%83%97%e3%83%ad%e3%82%b8%e3%82%a7%e3%82%af%e3%83%88%e3%81%ae%e9%81%8b%e5%96%b6 プロジェクトの運営 - Git での分散作業] を参照してください |
||
| − | $ git commit -am "''First commit.''" |
||
| − | }} |
||
| + | === Git ツール === |
||
| − | Go back and '''edit''' the commit message: |
||
| + | ==== リビジョンの選択 ==== |
||
| − | $ git commit --amend -m "''Message.''" |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-%e3%83%aa%e3%83%93%e3%82%b8%e3%83%a7%e3%83%b3%e3%81%ae%e9%81%b8%e6%8a%9e リビジョンの選択 - Git ツール] を参照してください |
||
| − | Many of the commands in this article take commits as arguments. A commit can be identified by any of the following: |
||
| + | ==== 対話的なステージング ==== |
||
| − | * Its 40-digit SHA-1 hash (the first 7 digits are usually sufficient to identify it uniquely) |
||
| − | * Any commit label such as a branch or tag name |
||
| − | * The label {{ic|HEAD}} always refers to the currently checked-out commit (usually the head of the branch, unless you used {{ic|git checkout}} to jump back in history to an old commit) |
||
| − | * Any of the above plus {{ic|~}} to refer to previous commits. For example, {{ic|HEAD~}} refers to one commit before {{ic|HEAD}} and {{ic|HEAD~5}} refers to five commits before {{ic|HEAD}}. |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-%e5%af%be%e8%a9%b1%e7%9a%84%e3%81%aa%e3%82%b9%e3%83%86%e3%83%bc%e3%82%b8%e3%83%b3%e3%82%b0 対話的なステージング - Git ツール] を参照してください |
||
| − | ==== 変更を閲覧 ==== |
||
| + | ==== 作業の隠しかたと消しかた ==== |
||
| − | '''Show differences''' between commits: |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-%e4%bd%9c%e6%a5%ad%e3%81%ae%e9%9a%a0%e3%81%97%e3%81%8b%e3%81%9f%e3%81%a8%e6%b6%88%e3%81%97%e3%81%8b%e3%81%9f 作業の隠しかたと消しかた - Git ツール] |
||
| − | $ git diff |
||
| + | ==== 作業内容への署名 ==== |
||
| − | '''Get''' a general '''overview''' of the changes: |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-%e4%bd%9c%e6%a5%ad%e5%86%85%e5%ae%b9%e3%81%b8%e3%81%ae%e7%bd%b2%e5%90%8d 作業内容への署名 - Git ツール] を参照してください |
||
| − | $ git status |
||
| + | ==== 検索 ==== |
||
| − | '''View history''' of changes (where "''-N''" is the number of latest commits): |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-%e6%a4%9c%e7%b4%a2 検索 - Git ツール] を参照してください |
||
| − | $ git log ''(-N)'' |
||
| − | ==== |
+ | ==== 履歴の書き換え ==== |
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-%e6%ad%b4%e5%8f%b2%e3%81%ae%e6%9b%b8%e3%81%8d%e6%8f%9b%e3%81%88 履歴の書き換え - Git ツール] を参照してください |
||
| − | Fixes and new features are usually tested in branches. When changes are satisfactory they can merged back into the default (master) branch. '''Create''' a branch, whose name accurately reflects its purpose: |
||
| + | ==== リセットコマンド ==== |
||
| − | $ git branch ''help-section-addition'' |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-%e3%83%aa%e3%82%bb%e3%83%83%e3%83%88%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89%e8%a9%b3%e8%aa%ac リセットコマンド詳説 - Git ツール] を参照してください |
||
| − | '''List''' branches: |
||
| + | ==== 高度なマージ ==== |
||
| − | $ git branch |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-%e9%ab%98%e5%ba%a6%e3%81%aa%e3%83%9e%e3%83%bc%e3%82%b8%e6%89%8b%e6%b3%95 高度なマージ手法 - Git ツール] を参照してください |
||
| − | '''Switch''' branches: |
||
| + | ==== Rerere ==== |
||
| − | $ git checkout ''branch'' |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-Rerere Rerere - Git ツール] を参照してください |
||
| − | '''Create and switch''': |
||
| + | ==== Git によるデバッグ ==== |
||
| − | $ git checkout -b ''branch'' |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-Git-%e3%81%ab%e3%82%88%e3%82%8b%e3%83%87%e3%83%90%e3%83%83%e3%82%b0 Git によるデバッグ - Git ツール] を参照してください |
||
| − | '''Merge''' a branch back to the master branch: |
||
| + | ==== サブモジュール ==== |
||
| − | $ git checkout master |
||
| − | $ git merge ''branch'' |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-%e3%82%b5%e3%83%96%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab サブモジュール - Git ツール] を参照してください |
||
| − | The changes will be merged if they do not conflict. If they do, the conflicts will be recorded. What is causing the conflicts can been seen with {{ic|git diff}}, then conflict resolution will need to be done manually. |
||
| + | ==== バンドル ==== |
||
| − | When done with a branch, '''delete''' it with: |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-%e3%83%90%e3%83%b3%e3%83%89%e3%83%ab%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%ae%e4%bd%9c%e6%88%90 バンドルファイルの作成 - Git ツール] を参照してください |
||
| − | $ git branch -d ''branch'' |
||
| − | === |
+ | ==== 置換 ==== |
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-Git-%e3%82%aa%e3%83%96%e3%82%b8%e3%82%a7%e3%82%af%e3%83%88%e3%81%ae%e7%bd%ae%e3%81%8d%e6%8f%9b%e3%81%88 Git オブジェクトの置き換え - Git ツール] を参照してください |
||
| − | ==== Adopting a good etiquette ==== |
||
| + | ==== 認証情報ストレージ ==== |
||
| − | * When considering contributing to an existing project, read and understand its license, as it may excessively limit your ability to change the code. Some licenses can generate disputes over the ownership of the code. |
||
| − | * Think about the project's community and how well you can fit into it. To get a feeling of the direction of the project, read any documentation and even the [[#History and versioning|log]] of the repository. |
||
| − | * When requesting to pull a commit, or submit a patch, keep it small and well documented; this will help the maintainers understand your changes and decide whether to merge them or ask you to make some amendments. |
||
| − | * If a contribution is rejected, do not get discouraged, it is their project after all. If it is important, discuss the reasoning for the contribution as clearly and as patiently as possible: with such an approach a resolution may eventually be possible. |
||
| + | [https://git-scm.com/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-%e8%aa%8d%e8%a8%bc%e6%83%85%e5%a0%b1%e3%81%ae%e4%bf%9d%e5%ad%98 認証情報の保存 - Git ツール] を参照してください |
||
| − | ==== リポジトリを複製 ==== |
||
| + | == ヒントとテクニック == |
||
| − | To begin contributing to a project, '''clone''' its repository: |
||
| + | === git-config の使用 === |
||
| − | $ git clone ''location'' ''folder'' |
||
| + | Git は、4つの INI タイプの設定ファイルからその構成を読み取ります。 |
||
| − | {{ic|''location''}} can be either a path or network address. Also, when cloning is done, the location is recorded so just a {{ic|git pull}} will be needed later. |
||
| + | * {{ic|/etc/gitconfig}} システム全体のデフォルト |
||
| − | ==== プルリクエスト ==== |
||
| + | * {{ic|~/.gitconfig}} と {{ic|~/.config/git/config}} (since 1.7.12) ユーザー固有の設定用 |
||
| + | * {{ic|.git/config}} リポジトリ固有の設定用 |
||
| + | これらのファイルは直接編集できますが、通常の方法は、以下の例に示すように ''git config'' を使用することです。 |
||
| − | After making and committing some changes, the contributor can ask the original author to merge them. This is called a ''pull request''. To '''pull''': |
||
| + | 現在設定されている変数を一覧表示します。 |
||
| − | $ git pull ''location'' master |
||
| + | $ git config {--local,--global,--system} --list |
||
| − | The ''pull'' command combines both ''fetching'' and ''merging''. If there are conflicts (e.g. the original author made changes in the same time span), then it will be necessary to manually fix them. |
||
| + | デフォルトのエディターを [[vim]] から [[nano]] に設定します。 |
||
| − | Alternatively, the original author can '''pick''' the '''changes''' wanting to be incorporated. Using the ''fetch'' option (and ''log'' option with a special {{ic|FETCH_HEAD}} symbol), the contents of the pull request can be viewed before deciding what to do: |
||
| + | $ git config --global core.editor "nano -w" |
||
| − | $ git fetch ''location'' master |
||
| − | $ git log -p HEAD..FETCH_HEAD |
||
| − | $ git merge ''location'' master |
||
| + | デフォルトのプッシュアクションを設定します。 |
||
| − | ==== リモートの使用 ==== |
||
| + | $ git config --global push.default simple |
||
| − | Remotes are tracked repositories, a ''label'' defining a location. They are commonly used for frequently accessed repositories. '''Create''' a remote: |
||
| + | ''git difftool'' に別のツールを設定します (デフォルトでは ''meld''): |
||
| − | $ git remote add ''label'' ''location'' |
||
| + | $ git config --global diff.tool vimdiff |
||
| − | '''Fetch''' a remote: |
||
| + | 詳細については、{{man|1|git-config}} および [https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration Git 構成] を参照してください。 |
||
| − | $ git fetch ''label'' |
||
| + | === 良いエチケットを採用する === |
||
| − | '''Show differences''' between master and a remote master: |
||
| + | * 既存のプロジェクトに貢献することを検討する場合、コードを変更する能力を過度に制限する可能性があるため、そのライセンスを読んで理解してください。ライセンスによっては、コードの所有権をめぐって紛争を引き起こす可能性があります。 |
||
| − | $ git log -p master..''label''/master |
||
| + | * プロジェクトのコミュニティと、自分がそこにどれだけ溶け込めるかを考えましょう。プロジェクトの方向性を知るために、あらゆるドキュメントや、リポジトリの [[#History and versioning|log]] を読んでください。 |
||
| + | * コミットをプルしたり、パッチを提出したりするときは、小規模で十分な文書化を心がけましょう。そうすることで、メンテナがあなたの変更を理解し、マージするか修正を依頼するかを判断しやすくなります。 |
||
| + | * もし、投稿が拒否されても、落ち込まないでください。重要なことであれば、その理由をできるだけ明確に、忍耐強く議論してください。 |
||
| + | === 認証の高速化 === |
||
| − | '''View''' remotes for the current repository: |
||
| + | Git サーバーにプッシュする度に認証が面倒なのをなんとかしたいと思っている場合、以下を使って下さい。 |
||
| − | $ git remote -v |
||
| + | * SSH 鍵を使って認証している場合、[[SSH 鍵#SSH エージェント|SSH エージェント]]を使って下さい。[[SSH#SSH の高速化]] や [[SSH#Keep alive]] も参照。 |
||
| − | When defining a remote that is a parent of the fork (the project lead), it is defined as ''upstream''. |
||
| + | * ユーザー名とパスワードを使って認証している場合、サーバーが SSH をサポートしているなら [[SSH 鍵]]に切り替えてください。もしくは [https://git-scm.com/docs/git-credential-cache git-credential-cache] や [https://git-scm.com/docs/git-credential-store git-credential-store] を使ってみて下さい。 |
||
| + | === git-credential-libsecret を認証情報ヘルパーとして使用する === |
||
| − | ==== リポジトリにプッシュ ==== |
||
| + | Git は [[GNOME/Keyring]] や [[KeePass]] のような org.freedesktop.secrets と互換性のあるキーリングから認証情報を取得することがあります。そのため、互換性のあるキーリングを一つセットアップし、キーリングが dbus に登録されているかどうかを確認します。 |
||
| − | After being given rights from the original authors, '''push''' changes with: |
||
| + | dbus-send --session --print-reply --dest=org.freedesktop.DBus / \ |
||
| − | $ git push ''location'' ''branch'' |
||
| + | org.freedesktop.DBus.GetConnectionUnixProcessID \ |
||
| + | string:org.freedesktop.secrets |
||
| + | 実行 |
||
| − | When {{ic|git clone}} is performed, it records the original location and gives it a remote name of {{ic|origin}}. So what '''typically''' is done is this: |
||
| + | git config --global credential.helper /usr/lib/git-core/git-credential-libsecret |
||
| − | $ git push origin master |
||
| + | その後 git をセットアップします。 |
||
| − | If the {{ic|--set-upstream}} option is used, the location is recorded so the next time just a {{ic|git push}} is necessary. |
||
| + | === git-credential-netrc を認証情報ヘルパーとして使用する === |
||
| − | ==== マージの対処 ==== |
||
| + | Git は、[https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html netrc] ファイルを読み取って認証情報にアクセスできます。まず、Git を netrc ヘルパースクリプトに誘導します。 |
||
| − | See [http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging#Basic-Merge-Conflicts Basic Merge Conflicts] in the Git Book for a detailed explanation on how to resolve merge conflicts. Merges are generally reversible. If wanting to back out of a merge one can usually use the {{ic|--abort}} command (e.g. {{ic|git merge --abort}} or {{ic|git pull --abort}}). |
||
| + | $ git config --global credential.helper /usr/share/git/credential/netrc/git-credential-netrc.perl |
||
| − | ==== メーリングリストにパッチを送信 ==== |
||
| + | 次に、{{ic|.netrc}} ファイルを [[作成]] します。 |
||
| − | If you want to send patches directly to a mailing list, you have to install the following packages: {{Pkg|perl-authen-sasl}}, {{Pkg|perl-net-smtp-ssl}} and {{Pkg|perl-mime-tools}}. |
||
| + | {{hc|~/.netrc| |
||
| − | Make sure you have configured you username and e-mail address, see [[#Basic configuration]]. |
||
| + | machine git-host |
||
| + | login username |
||
| + | password password |
||
| + | }} |
||
| + | 認証情報ヘルパーは [[gpg]] で暗号化されたファイル ({{ic|~/.netrc.gpg}}) もサポートします。 |
||
| − | '''Configure''' your '''e-mail''' settings: |
||
| + | === デフォルトプロトコル === |
||
| − | $ git config --global sendemail.smtpserver ''smtp.gmail.com'' |
||
| − | $ git config --global sendemail.smtpserverport ''587'' |
||
| − | $ git config --global sendemail.smtpencryption ''tls'' |
||
| − | $ git config --global sendemail.smtpuser ''foobar@gmail.com'' |
||
| + | 上述のように SSH で多重接続することで、Git over SSH の方が HTTPS よりも高速になります。また、(AUR など) サーバーによっては SSH を介して push することもできます。例えば、以下の設定をすると AUR でホストされているリポジトリで Git over SSH を設定します。 |
||
| − | Now you should be able to '''send''' the '''patch''' to the mailing list (see also [http://www.openembedded.org/wiki/How_to_submit_a_patch_to_OpenEmbedded#Sending_patches OpenEmbedded:How to submit a patch to OpenEmbedded#Sending patches]): |
||
| + | {{hc|~/.gitconfig|<nowiki> |
||
| − | $ git add ''filename'' |
||
| + | [url "ssh://aur@aur.archlinux.org/"] |
||
| − | $ git commit -s |
||
| + | insteadOf = https://aur.archlinux.org/ |
||
| − | $ git send-email --to=''openembedded-core@lists.openembedded.org'' --confirm=always -M -1 |
||
| + | insteadOf = http://aur.archlinux.org/ |
||
| + | insteadOf = git://aur.archlinux.org/ |
||
| + | </nowiki>}} |
||
| − | === |
+ | === Bash 補完 === |
| + | Bash の補完を有効にするには、[[Bash#設定ファイル|Bash のスタートアップファイル]]で {{ic|/usr/share/git/completion/git-completion.bash}} を source してください。もしくは、{{pkg|bash-completion}} をインストールしてください。 |
||
| − | ==== Searching the history ==== |
||
| + | === Git プロンプト === |
||
| − | {{ic|git log}} will give the history with a commit checksum, author, date, and the short message. For '''history''' with a '''long message''' (where the "''checksum''" can be truncated, as long as it is unique): |
||
| + | Git パッケージにはプロンプトスクリプトが付属しています。これを有効にするには、{{ic|/usr/share/git/completion/git-prompt.sh}} をソースし、{{ic|%s}} パラメータを使用してカスタムプロンプトを設定します。 |
||
| − | $ git show (''checksum'') |
||
| + | * [[Bash]] の場合: {{ic|1=PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '}} |
||
| − | '''Search''' for ''pattern'' in tracked files: |
||
| + | * [[zsh]] の場合: {{ic|1=setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '}} |
||
| + | Git リポジトリのディレクトリに変更すると、プロンプトが変化してブランチ名が表示されます。対応する環境変数を設定することで、追加の詳細がプロンプトに表示されるように設定できます。 |
||
| − | $ git grep ''pattern'' |
||
| + | {| class="wikitable" |
||
| − | '''Search''' in '''{{ic|.c}}''' and '''{{ic|.h}}''' files: |
||
| + | |+ |
||
| + | ! シェル変数 !! 情報 |
||
| + | |- |
||
| + | | GIT_PS1_SHOWDIRTYSTATE || ステージ済みの場合は '''+'''、未ステージの場合は '''*''' |
||
| + | |- |
||
| + | | GIT_PS1_SHOWSTASHSTATE || スタッシュが存在する場合は '''$''' |
||
| + | |- |
||
| + | | GIT_PS1_SHOWUNTRACKEDFILES || 追跡されていないファイルが存在する場合は '''%''' |
||
| + | |- |
||
| + | | GIT_PS1_SHOWUPSTREAM || 上流からの進み・戻り・分岐 ('''<,>,<>''') |
||
| + | |- |
||
| + | | GIT_PS1_STATESEPARATOR || ブランチ名と状態記号の間の区切り文字 |
||
| + | |- |
||
| + | | GIT_PS1_DESCRIBE_STYLE || HEAD が切り離されている場合、タグまたはブランチに関連するコミットを表示します |
||
| + | |- |
||
| + | | GIT_PS1_SHOWCOLORHINTS || カラーで表示する |
||
| + | |} |
||
| + | 環境変数の完全なドキュメントは、スクリプトのコメントで参照できます。 |
||
| − | $ git grep ''pattern'' -- '*.[ch]' |
||
| + | {{Note| |
||
| − | ==== Versioning for release ==== |
||
| + | * {{ic|$(__git_ps1)}} が {{ic|((unknown))}} と返す場合、何もリポジトリが含まれていない {{ic|.git}} フォルダがカレントディレクトリに存在するため Git が認識しなくなっています。{{ic|~/.gitconfig}} ではなく間違って {{ic|~/.git/config}} に Git の設定ファイルを作成した場合などに発生します。 |
||
| + | * 非常に大規模なリポジトリでプロンプトに遅延が発生している場合は、{{ic|GIT_PS1_SHOWUNTRACKEDFILES}} オプションが原因である可能性があります。このオプションは、新しいファイルを検出するたびに完全なディレクトリツリースキャンをトリガーし、パフォーマンスに顕著な影響を与えます。 これらのリポジトリに対してこのオプションをローカルで無効にするには、コマンド {{ic|git config --local bash.showUntrackedFiles false}} を使用できます。 |
||
| + | }} |
||
| + | もしくは、{{AUR|bash-git-prompt}} や {{AUR|gittify}} など [[AUR]] にある git シェルプロンプトのカスタマイズパッケージを利用することもできます。 |
||
| − | '''Tag''' commits for versioning: |
||
| + | === ビジュアル表現 === |
||
| − | $ git tag 2.14 ''checksum'' |
||
| + | 作業量を把握するため: |
||
| − | ''Tagging'' is generally done for [https://www.drupal.org/node/1066342 releasing/versioning] but it can be any string. Generally annotated tags are used, because they get added to the Git database. '''Tag''' the '''current''' commit with: |
||
| − | $ git |
+ | $ git diff --stat |
| + | ''git log'' をフォーク表現: |
||
| − | '''List''' tags: |
||
| − | $ git |
+ | $ git log --graph --oneline --decorate |
| + | ''git log'' グラフのエイリアス (つまり ''git graph'' は装飾されたバージョンを表示する): |
||
| − | '''Delete''' a tag: |
||
| + | $ git config --global alias.graph 'log --graph --oneline --decorate' |
||
| − | $ git tag -d 2.08 |
||
| + | === コミットのヒント === |
||
| − | '''Update remote''' tags with a separate: |
||
| + | 前のコミットにリセット (非常に危険、指定したコミットまですべて消去されます): |
||
| − | $ git push --tags |
||
| + | $ git reset --hard HEAD^ |
||
| − | ==== Organizing commits ==== |
||
| + | リポジトリのアドレスが変更された場合、そのリモートロケーションを更新する必要があります: |
||
| − | Before submitting a pull request it may be desirable to '''consolidate/organize''' the commits. This is done with the {{ic|git rebase}} interactive option: |
||
| + | $ git remote set-url origin git@''address'':''user''/''repo''.git |
||
| − | $ git rebase -i ''checksum'' |
||
| + | あるいは、{{ic|.git/config}} を編集して新しい場所を指定します。 |
||
| − | This will open the editor with a summary of all the commits in the range specified; in this case including the newest ({{ic|HEAD}}) to, but excluding, {{ic|''checksum''}}. Or to use a number notation, use for example {{ic|HEAD~3}}, which will rebase the last three commits: |
||
| + | Signed-off-by line append (プロジェクトによっては必要な、名前と電子メールの署名がコミットに追加されます): |
||
| − | pick d146cc7 Mountpoint test. |
||
| − | pick 4f47712 Explain -o option in readme. |
||
| − | pick 8a4d479 Rename documentation. |
||
| + | $ git commit -s |
||
| − | Editing the action in the first column will dictate how the rebase will be done. The options are: |
||
| + | Signed-off-by は自動的にパッチに追加されます ({{ic|git format-patch ''commit''}} を使用する場合): |
||
| − | * {{ic|pick}} — Apply this commit as is (the default). |
||
| − | * {{ic|edit}} — Edit files and/or commit message. |
||
| − | * {{ic|reword}} — Edit commit message. |
||
| − | * {{ic|squash}} — Merge/fold into previous commit. |
||
| − | * {{ic|fixup}} — Merge/fold into previous commit discarding its message. |
||
| + | $ git config --local format.signoff true |
||
| − | The commits can be re-ordered or erased from the history (but be very careful with these). After editing the file, Git will perform the specified actions; if prompted to resolve merge problems, fix them and continue with {{ic|git rebase --continue}} or back out with the {{ic|git rebase --abort}} command. |
||
| + | 変更されたファイルの特定の部分をコミットします。これは、多数の変更があり、複数のコミットに分けたほうがよい場合に有用です。 |
||
| − | {{Note|Squashing commits is only used for local commits, it will cause troubles on a repository that is shared by other people.}} |
||
| + | $ git add -p |
||
| − | == 高度な設定 == |
||
| + | === コミットへの署名 === |
||
| − | Git reads its configuration from a few INI-type configuration files: |
||
| + | Git では、コミットやタグに [[GnuPG]] を使って署名することができます。[https://git-scm.com/book/en/Git-Tools-Signing-Your-Work Signing Your Work] を参照してください。 |
||
| − | * Each repository contains a {{ic|.git/config}} file for specific configuration. |
||
| − | * Each user has a {{ic|$HOME/.gitconfig}} file for fallback values. |
||
| − | * {{ic|/etc/gitconfig}} is used for system-wide defaults. |
||
| + | {{Note|GPG 署名に [[pinentry]] curses を使用するには、 {{ic|1=export GPG_TTY=$(tty)}} (あるいは pinentry-tty を使用) してください。そうしないと GPG が現在ロック状態にある場合に署名が失敗します (pin を要求できないため)。}} |
||
| − | These files can be edited directly, but the usual method is to use {{ic|git config}}, as shown in the examples below. |
||
| + | Git が自動的にコミットに署名するように設定するには: |
||
| − | List the currently set variables: |
||
| − | $ git config |
+ | $ git config --global commit.gpgSign true |
| + | === マスター以外のブランチで作業 === |
||
| − | Set the default editor from [[vim]] to [[nano]]: |
||
| + | ときに、メンテナからブランチで作業するように要求されることがあります。使われるブランチの名前は {{ic|devel}} や {{ic|testing}} などが一般的です。まずはリポジトリを複製します。 |
||
| − | $ git config --global core.editor "nano -w" |
||
| + | master 以外のブランチを開くには ({{ic|git clone}} で master ブランチしか表示されない場合、{{ic|git branch -a}} で他のブランチを表示できます): |
||
| − | Set the default push action: |
||
| + | $ git checkout -b ''branch'' origin/''branch'' |
||
| − | $ git config --global push.default simple |
||
| + | 通常通り編集を行ってください。ただし以下のコマンドを使ってリポジトリツリーを同期させてください: |
||
| − | Set a different tool for {{ic|git difftool}} (''meld'' by default): |
||
| − | $ git |
+ | $ git pull --all |
| + | $ git push --all |
||
| + | === メーリングリストにパッチを送信 === |
||
| − | See [https://www.kernel.org/pub/software/scm/git/docs/git-config.html git-config(1)] and [http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration Git Configuration] for more information. |
||
| + | メーリングリストに直接パッチを送る場合、次のパッケージをインストールする必要があります: {{Pkg|perl-authen-sasl}}, {{Pkg|perl-net-smtp-ssl}}, {{Pkg|perl-mime-tools}} |
||
| − | === SSH の高速化 === |
||
| + | ユーザー名とメールアドレスを設定したか確認してください、[[Git#基本設定|基本設定]] を参照 |
||
| − | Often if you find yourself pushing constantly to a few common servers, you may wish to remove the hassle of setting your username for each repository. |
||
| + | メールアドレスを設定: |
||
| − | If you do not already have the keys created, make them now. |
||
| + | $ git config --global sendemail.smtpserver ''smtp.gmail.com'' |
||
| − | $ ssh-keygen -N ’’ -b 4096 -t rsa -f ~/.ssh/aur -C "''user@domain.com''" |
||
| + | $ git config --global sendemail.smtpserverport ''587'' |
||
| − | $ ssh-keygen -N ’’ -b 4096 -t rsa -f ~/.ssh/github -C "''user@domain.com''" |
||
| + | $ git config --global sendemail.smtpencryption ''tls'' |
||
| + | $ git config --global sendemail.smtpuser ''foobar@gmail.com'' |
||
| + | これでメーリングリストにパッチを送信することができます ([http://www.openembedded.org/wiki/How_to_submit_a_patch_to_OpenEmbedded#Sending_patches OpenEmbedded:How to submit a patch to OpenEmbedded#Sending patches] を参照): |
||
| − | Add the resulting public keys to your accounts. |
||
| + | $ git add ''filename'' |
||
| − | Additionally, reusing the same SSH connection will drastically improve the time {{ic|git push}} takes. |
||
| + | $ git commit -s |
||
| + | $ git send-email --to=''openembedded-core@lists.openembedded.org'' --confirm=always -M -1 |
||
| + | === 大規模な git リポジトリの操作 === |
||
| − | $ mkdir -p ~/.ssh/sockets/ |
||
| + | 大規模なリモートリポジトリを操作する場合、大量のデータをフェッチする必要があります。次の例では、Linux カーネルを使用して、そのようなコードベースを操作する方法を示しています。 |
||
| − | You may wish to adjust the {{ic|ServerAliveInterval}} depending on your connection. |
||
| + | ==== リポジトリ全体を取得する ==== |
||
| − | {{hc|~/.ssh/config| |
||
| − | Host * |
||
| − | ControlMaster auto |
||
| − | ControlPath ~/.ssh/sockets/%r@%h-%p |
||
| − | ControlPersist 8760h |
||
| − | '''ServerAliveInterval 5''' |
||
| − | ServerAliveCountMax 1 |
||
| − | TCPKeepAlive yes |
||
| + | 最も簡単な解決策は、リポジトリ全体を取得することです。 |
||
| − | Host aur-dev.archlinux.org |
||
| − | IdentityFile ~/.ssh/aur |
||
| − | User aur |
||
| − | Port 2222 |
||
| + | $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git |
||
| − | Host github.com |
||
| − | IdentityFile ~/.ssh/github |
||
| − | User [username here] |
||
| − | }} |
||
| + | {{Note|{{ic|git clone}} を中断すると再開できません}} |
||
| − | === Protocol Defaults === |
||
| + | {{ic|git pull}} でリポジトリを更新できます。 |
||
| − | If you are running a multiplexed SSH connection as shown above, Git over SSH might be faster than HTTPS. Also, you will not have to enter your password on every push until your multiplexed connection goes down (and only if there is a passphrase on it). For example, the following config will set Git over SSH for any repository hosted on GitHub. |
||
| + | ==== リポジトリの部分的な取得 ==== |
||
| − | {{hc|~/.gitconfig| |
||
| − | [url "ssh://git@github.com/"] |
||
| − | insteadOf = https://github.com/ |
||
| − | insteadOf = http://github.com/ |
||
| − | insteadOf = git://github.com/ |
||
| − | }} |
||
| + | ローカルリポジトリをオリジンのより小さなサブセットに制限するには、たとえば v4.14 以降でバグを二分するために、浅いクローンを使用します。 |
||
| − | Optionally, the Git protocol could be used for pulling instead. |
||
| + | $ git clone --shallow-exclude v4.13 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git |
||
| − | {{Warning|There is absolutely no encryption or verification with the server using the Git protocol by itself. Please be careful with software after obtaining through this method.}} |
||
| + | v4.14 以降は入手できますが、v4.13 以前は入手できません。 |
||
| − | {{hc|~/.gitconfig| |
||
| − | [url "ssh://git@github.com/"] |
||
| − | pushInsteadOf = https://github.com/ |
||
| − | [url "git://github.com/"] |
||
| − | insteadOf = https://github.com/ |
||
| − | insteadOf = http://github.com/ |
||
| − | }} |
||
| + | すべての履歴を無視して、最新のスナップショットのみが必要な場合。(tarball が利用可能で、それで十分な場合は、それを選択してください。git リポジトリからダウンロードするには、より多くの帯域幅が必要です。) 次の方法で取得できます。 |
||
| − | {{Note|Some corporate firewalls block port 9418/TCP, which the Git protocol uses. In those situations, Git over SSH or HTTPS will likely be the best option.}} |
||
| + | $ git clone --depth 1 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git |
||
| − | === Bash 補完 === |
||
| + | 次の2つの例に示すように、後で古いコミットを取得できます。 |
||
| − | In order to enable Bash completion, source {{ic|/usr/share/git/completion/git-completion.bash}} in a [[Bash#Configuration_files|Bash startup file]]. Alternatively, install {{pkg|bash-completion}}. |
||
| + | $ git fetch --tags --shallow-exclude v4.1 |
||
| − | === Git プロンプト === |
||
| + | $ git fetch --tags --shallow-since 2016-01-01 |
||
| + | {{Note|{{ic|--tags}} がないと、タグは取得されません。}} |
||
| − | The Git package comes with a prompt script. To enable it, source the {{ic|/usr/share/git/completion/git-prompt.sh}} script in a [[Autostarting#Shells|shell startup file]], then set a custom prompt with the {{ic|%s}} parameter: |
||
| + | ==== 他のブランチを取得する ==== |
||
| − | * For [[Bash]]: {{ic|1=PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '}} |
||
| − | * For [[zsh]]: {{ic|1=PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '}} |
||
| + | 上記の例では、ローカル リポジトリはメインラインカーネル、つまり ''最新の開発が行われた'' カーネルのみを追跡します。たとえば、最新の 4.14 ブランチなど、最新の ''LTS'' が必要な場合、次の方法で取得できます。 |
||
| − | When changing to a directory of a Git repository, the prompt will change to show the branch name. Extra details can be set to be shown by the prompt: |
||
| + | $ git remote set-branches --add origin linux-4.17.y |
||
| − | {| class="wikitable" |
||
| + | $ git fetch |
||
| − | |+ |
||
| + | $ git branch --track linux-4.17.y origin/linux-4.17.y |
||
| − | ! Shell variable !! Information |
||
| − | |- |
||
| − | | GIT_PS1_SHOWDIRTYSTATE || '''+''' for staged, '''*''' if unstaged. |
||
| − | |- |
||
| − | | GIT_PS1_SHOWSTASHSTATE || '''$''' if something is stashed. |
||
| − | |- |
||
| − | | GIT_PS1_SHOWUNTRACKEDFILES || '''%''' if there are untracked files. |
||
| − | |- |
||
| − | | GIT_PS1_SHOWUPSTREAM || '''<,>,<>''' behind, ahead, or diverged from upstream. |
||
| − | |} |
||
| + | 最後の行は必須ではありませんが、おそらく必要でしょう。 |
||
| − | {{ic|GIT_PS1_SHOWUPSTREAM}} will need to be set to {{ic|auto}} for changes to take effect. |
||
| + | (必要なブランチの名前を知るために、一般的なルールはありません。gitweb のインターフェイスにある "ref" リンクを見れば、推測することができます。) |
||
| + | linux-4.17.y のスナップショットについては、次のようにします。 |
||
| − | {{Note|If you experience that {{ic|$(__git_ps1)}} returns {{ic|((unknown))}}, then there is a {{ic|.git}} folder in your current directory which does not contain any repository, and therefore Git does not recognize it. This can, for example, happen if you mistake Git's configuration file to be {{ic|~/.git/config}} instead of {{ic|~/.gitconfig}}.}} |
||
| + | $ git checkout -b linux-4.17.y |
||
| − | == 高度な使い方 == |
||
| + | または、別のディレクトリに展開するには、 |
||
| − | To get an idea of the amount of work done: |
||
| + | $ mkdir /path/to/src-4.17; cd /path/to /src-4.17 |
||
| − | $ git diff --stat |
||
| + | $ git clone --no-local --depth 1 -b linux-4.17.y ../linux-stable |
||
| + | いつものように、{{ic|git pull}} を実行してスナップショットを更新します。 |
||
| − | {{ic|git log}} with forking representation: |
||
| + | ==== 代替案 ==== |
||
| − | $ git log --graph --oneline --decorate |
||
| + | Virtual File System for Git (VFS for Git) は、ローカルのリポジトリがなくても git のリポジトリにアクセスできるようにするものです。([https://blogs.msdn.microsoft.com/bharry/2017/05/24/the-largest-git-repo-on-the-planet/ この Microsoft ブログ] や [[wikipedia:Virtual File System for Git|Wikipedia article]] を参照してください。) |
||
| − | {{ic|git log}} graph alias (i.e. {{ic|git graph}} will show a decorated version): |
||
| + | これは、gvfs と scalar を含む git の Microsoft のフォークである {{AUR|git-vfs}} で利用可能です。 |
||
| − | $ git config --global alias.graph 'log --graph --oneline --decorate' |
||
| − | |||
| − | Reset to previous commit (very dangerous, erases everything to specified commit): |
||
| − | |||
| − | $ git reset --hard HEAD^ |
||
| − | |||
| − | If a repository address gets changed, its remote location will need to be updated: |
||
| − | |||
| − | $ git remote set-url origin git@''address'':''user''/''repo''.git |
||
| − | |||
| − | Signed-off-by line append (a name-email signature is added to the commit which is required by some projects): |
||
| − | |||
| − | $ git commit -s |
||
| − | |||
| − | Signed-off-by automatically append to patches (when using {{ic|git format-patch ''commit''}}): |
||
| − | |||
| − | $ git config --local format.signoff true |
||
| − | |||
| − | Commit specific parts of files that have changed. This is useful if there are a large number of changes made that would be best split into several commits: |
||
| − | |||
| − | $ git add -p |
||
| − | |||
| − | === マスター以外のブランチで作業 === |
||
| − | |||
| − | Occasionally a maintainer will ask that work be done on a branch. These branches are often called {{ic|devel}} or {{ic|testing}}. Begin by cloning the repository. |
||
| − | |||
| − | To enter another branch beside master ({{ic|git clone}} only shows master branch but others still exist, {{ic|git branch -a}} to show): |
||
| − | |||
| − | $ git checkout -b ''branch'' origin/''branch'' |
||
| − | |||
| − | Now edit normally; however to keep the repository tree in sync be sure to use both: |
||
| − | |||
| − | $ git pull --all |
||
| − | $ git push --all |
||
| − | |||
| − | == Git サーバー == |
||
| − | |||
| − | How to set up connecting to repositories using varying protocols. |
||
| − | |||
| − | === SSH === |
||
| − | |||
| − | To use the SSH protocol, first set up a public SSH key; for that follow the guide at [[SSH keys]]. To set up a SSH server, follow the [[SSH]] guide. |
||
| − | |||
| − | With SSH working and a key generated, paste the contents of {{ic|~/.ssh/id_rsa.pub}} to {{ic|~/.ssh/authorized_keys}} (be sure it is all on one line). Now the Git repository can be accessed with SSH by doing: |
||
| − | |||
| − | $ git clone ''user''@''foobar.com'':''my_repository''.git |
||
| − | |||
| − | You should now get an SSH yes/no question, if you have the SSH client setting {{ic|StrictHostKeyChecking}} set to {{ic|ask}} (the default). Type {{ic|yes}} followed by {{ic|Enter}}. Then you should have your repository checked out. Because this is with SSH, you also have commit rights now. |
||
| − | |||
| − | To modify an existing repository to use SSH, the remote location will need to be redefined: |
||
| − | |||
| − | $ git remote set-url origin git@localhost:''my_repository''.git |
||
| − | |||
| − | Connecting on a port other than 22 can be configured on a per-host basis in {{ic|/etc/ssh/ssh_config}} or {{ic|~/.ssh/config}}. To set up ports for a repository, if the repository is in {{ic|~/}} and using 443 for the port: |
||
| − | |||
| − | {{hc|~/.git/config|2= |
||
| − | [remote "origin"] |
||
| − | url = ssh://''user''@''foobar''.com:443/~''my_repository''/repo.git |
||
| − | }} |
||
| − | |||
| − | === Smart HTTP === |
||
| − | |||
| − | Git is able to use the HTTP(S) protocol as efficiently as the SSH or Git protocols, by utilizing the git-http-backend. Furthermore it is not only possible to clone or pull from repositories, but also to push into repositories over HTTP(S). |
||
| − | |||
| − | The setup for this is rather simple as all you need to have installed is the Apache web server ({{pkg|apache}}, with {{ic|mod_cgi}}, {{ic|mod_alias}}, and {{ic|mod_env}} enabled) and of course, {{pkg|git}}. |
||
| − | |||
| − | Once you have your basic setup running, add the following to your Apache configuration file, which is usually located at: |
||
| − | |||
| − | {{hc|/etc/httpd/conf/httpd.conf| |
||
| − | <Directory "/usr/lib/git-core*"> |
||
| − | Require all granted |
||
| − | </Directory> |
||
| − | |||
| − | SetEnv GIT_PROJECT_ROOT /srv/git |
||
| − | SetEnv GIT_HTTP_EXPORT_ALL |
||
| − | ScriptAlias /git/ /usr/lib/git-core/git-http-backend/ |
||
| − | }} |
||
| + | === 機密情報のフィルタリング === |
||
| − | This assumes your Git repositories are located at {{ic|/srv/git}} and that you want to access them via something like: {{ic|<nowiki>http(s)://your_address.tld/git/your_repo.git</nowiki>}}. |
||
| + | 時には、ソフトウェアが平文のパスワードを設定ファイルに保存し、キーリングに接続するのとは対照的にすることがあります。このような場合、git clean-filters は機密情報を誤ってコミットしてしまうのを防ぐために便利です。たとえば、次のファイルでは "some-dotfile" というファイルにフィルタを割り当てています。 |
||
| − | {{Note|Make sure that Apache can read and write to your repositories.}} |
||
| + | {{hc|.gitattributes|<nowiki> |
||
| − | For more detailed documentation, visit the following links: |
||
| + | some-dotfile filter=remove-pass |
||
| − | * http://progit.org/2010/03/04/smart-http.html |
||
| + | </nowiki>}} |
||
| − | * https://www.kernel.org/pub/software/scm/git/docs/v1.7.10.1/git-http-backend.html |
||
| + | "some-dotfile" というファイルが git にチェックインされると、git はチェックイン前にこのファイルに対して "remove-pass" というフィルタを実行します。このフィルターは、git-configuration ファイルで定義しておく必要があります。 |
||
| − | === Git === |
||
| + | {{hc|.git/config|<nowiki> |
||
| − | {{Note|The Git protocol only allows read access.}} |
||
| + | [filter "remove-pass"] |
||
| + | clean = "sed -e 's/^password=.*/#password=TODO/'" |
||
| + | </nowiki>}} |
||
| + | {{Note|sed 式の特殊文字をエスケープすることは、この文脈では [https://stackoverflow.com/questions/49652495/git-filter-and-sed-fight-over トリッキーな作業] になります。git は2つのバックスラッシュを1つに変え、一方 git がコマンドを実行するために呼び出すシェルは、2つのバックスラッシュを再び1つに変えることを思い出してください。詳しくは、[https://stackoverflow.com/a/49654653 Git filter and sed fight over `$`] をご覧ください。}} |
||
| − | [[start|Start and enable]] {{ic|git-daemon.socket}}. |
||
| + | === HTML ヘルプファイル === |
||
| − | The daemon is started with the following options: |
||
| + | {{AUR|git-htmldocs}} をインストールすることで、{{ic|git help}} のドキュメントを HTML 形式で利用することもできます。インストール後、HTML ドキュメントには {{ic|-w}} フラグを付けてアクセスすることができます。例えば |
||
| − | ExecStart=-/usr/lib/git-core/git-daemon --inetd --export-all --base-path=/srv/git |
||
| + | $ git help -w merge |
||
| − | Repositories placed in {{ic|/srv/git/}} will be recognized by the daemon. Clients can connect with something similar to: |
||
| + | {{ic|git config}} オプションを設定すると、デフォルトで HTML ドキュメントを読み込むことができます。 |
||
| − | $ git clone git://''location''/''repository''.git |
||
| + | $ git config --global help.format html |
||
| − | === アクセス権限の設定 === |
||
| + | == 拡張機能 == |
||
| − | To restrict read and/or write access, use standard Unix permissions. Refer to http://sitaramc.github.com/gitolite/doc/overkill.html{{Dead link|2013|11|06}} ([https://web.archive.org/web/20111004134500/http://sitaramc.github.com/gitolite/doc/overkill.html archive.org mirror]) for more information. |
||
| + | * {{App|gitflow-avh|[https://nvie.com/posts/a-successful-git-branching-model/ Vincent Driessen の分岐モデル] で git を拡張します。AVH Edition はより多くの機能を追加します。|https://github.com/petervanderdoes/gitflow|{{AUR|gitflow-avh}}}} |
||
| − | For fine-grained access management, refer to [[gitolite]] and [[gitosis]]. |
||
| + | * {{App|git-extras|git 用のいくつかのユーティリティ (リポジトリの概要、repl、変更ログの人数、作成者のコミット率など)|https://github.com/tj/git-extras|{{AUR|git-extras}}}} - [https://ohmyz.sh oh-my-zsh] を使用している場合、[https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git-extras git-extras プラグイン] を有効にして下さい。 |
||
| + | * {{App|gitmoji-cli|A [https://gitmoji.dev/ gitmoji] コミットメッセージで gitmojis を使用するためのインタラクティブな NodeJS クライアント。|https://github.com/carloscuesta/gitmoji-cli|{{AUR|nodejs-gitmoji-cli}}}} |
||
== 参照 == |
== 参照 == |
||
| − | * [ |
+ | * [https://git-scm.com/book Pro Git book] |
* [http://gitref.org/ Git Reference] |
* [http://gitref.org/ Git Reference] |
||
* https://www.kernel.org/pub/software/scm/git/docs/ |
* https://www.kernel.org/pub/software/scm/git/docs/ |
||
| 561行目: | 485行目: | ||
* [http://nathanhoad.net/git-workflow-forks-remotes-and-pull-requests Git overall2] |
* [http://nathanhoad.net/git-workflow-forks-remotes-and-pull-requests Git overall2] |
||
* https://wiki.videolan.org/Git |
* https://wiki.videolan.org/Git |
||
| − | * [https://gist.github.com/grawity/4392747 |
+ | * [https://gist.github.com/grawity/4392747 GitHub が用意しているプロトコルの比較] |
2025年1月13日 (月) 18:06時点における最新版
関連記事
Git は Linux カーネルの創設者である Linus Torvalds によって設計・開発されたバージョン管理システム (VCS) です。現在 Git は Linux カーネルのソースの管理だけでなく、様々な他のプロジェクトにも使われており、Arch Linux プロジェクトもそれに含まれます。
目次
- 1 インストール
- 2 基本設定
- 3 使い方
- 4 ヒントとテクニック
- 4.1 git-config の使用
- 4.2 良いエチケットを採用する
- 4.3 認証の高速化
- 4.4 git-credential-libsecret を認証情報ヘルパーとして使用する
- 4.5 git-credential-netrc を認証情報ヘルパーとして使用する
- 4.6 デフォルトプロトコル
- 4.7 Bash 補完
- 4.8 Git プロンプト
- 4.9 ビジュアル表現
- 4.10 コミットのヒント
- 4.11 コミットへの署名
- 4.12 マスター以外のブランチで作業
- 4.13 メーリングリストにパッチを送信
- 4.14 大規模な git リポジトリの操作
- 4.15 機密情報のフィルタリング
- 4.16 HTML ヘルプファイル
- 5 拡張機能
- 6 参照
インストール
git パッケージを インストール して下さい。開発版の場合は、git-gitAUR パッケージをインストールします。git svn、git gui、gitk などのツールを使用する場合は、オプションの依存関係を確認してください。
グラフィカルフロントエンド
- Giggle — Git の GTK フロントエンド
- GitAhead — 組み込みの Merge Tool を含むグラフィカル Git クライアント
- Git Cola — Python で書かれた Git 用の洗練された強力なグラフィカル ユーザーインターフェイス
- Git Extensions — コマンドラインを使用せずに Git を制御できる Git のグラフィカルユーザーインターフェイス
- gitg — Git リポジトリを表示するための GNOME GUI クライアント
- git-gui — Git への Tcl/Tk ベースの移植可能なグラフィカルインターフェイス
- GitHub Desktop — GitHub チームによって構築された Electron ベースのグラフィカルユーザーインターフェイス
- gitk — Tcl/Tk ベースの Git リポジトリブラウザ
- Guitar — Git GUI クライアント
- lazygit — git コマンド用のシンプルなターミナル UI
- QGit — リビジョン履歴を参照し、パッチの内容と変更されたファイルを表示し、さまざまな開発ブランチをグラフィカルにたどる Git GUI ビューア
- RabbitVCS — 使用しているバージョン管理システムへのシンプルで直接的なアクセスを提供するために作成されたグラフィカルツールのセット
- Sublime Merge — Sublime Text のメーカーによる Git クライアント
- Tig — git 用の ncurses ベースのテキストモードインターフェイス
- ungit — git の汎用性を犠牲にすることなく、git に使いやすさをもたらします
基本設定
Git を使うには少なくとも名前とメールアドレスを設定する必要があります:
$ git config --global user.name "John Doe" $ git config --global user.email "johndoe@foobar.com"
こちらも参照 Getting Started - First-Time Git Setup
他の設定については #高度な設定 を見て下さい。
使い方
Gitリポジトリは、リビジョン履歴やその他のメタデータを保持する .git ディレクトリ内に含まれています。リポジトリによって追跡されるディレクトリは、デフォルトでは親ディレクトリであり、作業ディレクトリ(working directory)と呼ばれます。作業ツリー(working tree)内の変更は、リポジトリに記録(コミット)する前にステージングする必要があります。また、Gitを使用すると、以前にコミットされた作業ツリーのファイルを復元することもできます。
Getting Started - Git Basics を参照してください。
Git リポジトリの取得
Git リポジトリの取得 - Git の基本 を参照してください
変更の記録
変更内容のリポジトリへの記録 - Git の基本 を参照してください
コミット履歴の閲覧
コミット履歴の閲覧 - Git の基本 を参照してください
元に戻す
作業のやり直し - Git の基本 を参照してください
リモートの操作
リモートでの作業 - Git の基本 を参照してください
ブランチ
ブランチの概要 - Git のブランチ機能 を参照してください
基本的なブランチとマージ
ブランチとマージの基本 - Git のブランチ機能 を参照してください
ブランチ管理
ブランチ管理 - Git のブランチ機能 を参照してください
ブランチでの作業の流れ
ブランチでの作業の流れ - Git のブランチ機能 を参照してください
リモートブランチ
リモートブランチ - Git のブランチ機能 を参照してください
リベース
リベース - Git のブランチ機能 を参照してください
コラボレーション
分散ワークフロー
分散作業の流れ - Git での分散作業 を参照してください
プロジェクトへの貢献
プロジェクトへの貢献 - Git での分散作業 を参照してください
プロジェクトの運営
プロジェクトの運営 - Git での分散作業 を参照してください
Git ツール
リビジョンの選択
リビジョンの選択 - Git ツール を参照してください
対話的なステージング
対話的なステージング - Git ツール を参照してください
作業の隠しかたと消しかた
作業内容への署名
作業内容への署名 - Git ツール を参照してください
検索
検索 - Git ツール を参照してください
履歴の書き換え
履歴の書き換え - Git ツール を参照してください
リセットコマンド
リセットコマンド詳説 - Git ツール を参照してください
高度なマージ
高度なマージ手法 - Git ツール を参照してください
Rerere
Rerere - Git ツール を参照してください
Git によるデバッグ
Git によるデバッグ - Git ツール を参照してください
サブモジュール
サブモジュール - Git ツール を参照してください
バンドル
バンドルファイルの作成 - Git ツール を参照してください
置換
Git オブジェクトの置き換え - Git ツール を参照してください
認証情報ストレージ
認証情報の保存 - Git ツール を参照してください
ヒントとテクニック
git-config の使用
Git は、4つの INI タイプの設定ファイルからその構成を読み取ります。
/etc/gitconfigシステム全体のデフォルト~/.gitconfigと~/.config/git/config(since 1.7.12) ユーザー固有の設定用.git/configリポジトリ固有の設定用
これらのファイルは直接編集できますが、通常の方法は、以下の例に示すように git config を使用することです。
現在設定されている変数を一覧表示します。
$ git config {--local,--global,--system} --list
デフォルトのエディターを vim から nano に設定します。
$ git config --global core.editor "nano -w"
デフォルトのプッシュアクションを設定します。
$ git config --global push.default simple
git difftool に別のツールを設定します (デフォルトでは meld):
$ git config --global diff.tool vimdiff
詳細については、git-config(1) および Git 構成 を参照してください。
良いエチケットを採用する
- 既存のプロジェクトに貢献することを検討する場合、コードを変更する能力を過度に制限する可能性があるため、そのライセンスを読んで理解してください。ライセンスによっては、コードの所有権をめぐって紛争を引き起こす可能性があります。
- プロジェクトのコミュニティと、自分がそこにどれだけ溶け込めるかを考えましょう。プロジェクトの方向性を知るために、あらゆるドキュメントや、リポジトリの log を読んでください。
- コミットをプルしたり、パッチを提出したりするときは、小規模で十分な文書化を心がけましょう。そうすることで、メンテナがあなたの変更を理解し、マージするか修正を依頼するかを判断しやすくなります。
- もし、投稿が拒否されても、落ち込まないでください。重要なことであれば、その理由をできるだけ明確に、忍耐強く議論してください。
認証の高速化
Git サーバーにプッシュする度に認証が面倒なのをなんとかしたいと思っている場合、以下を使って下さい。
- SSH 鍵を使って認証している場合、SSH エージェントを使って下さい。SSH#SSH の高速化 や SSH#Keep alive も参照。
- ユーザー名とパスワードを使って認証している場合、サーバーが SSH をサポートしているなら SSH 鍵に切り替えてください。もしくは git-credential-cache や git-credential-store を使ってみて下さい。
git-credential-libsecret を認証情報ヘルパーとして使用する
Git は GNOME/Keyring や KeePass のような org.freedesktop.secrets と互換性のあるキーリングから認証情報を取得することがあります。そのため、互換性のあるキーリングを一つセットアップし、キーリングが dbus に登録されているかどうかを確認します。
dbus-send --session --print-reply --dest=org.freedesktop.DBus / \
org.freedesktop.DBus.GetConnectionUnixProcessID \
string:org.freedesktop.secrets
実行
git config --global credential.helper /usr/lib/git-core/git-credential-libsecret
その後 git をセットアップします。
git-credential-netrc を認証情報ヘルパーとして使用する
Git は、netrc ファイルを読み取って認証情報にアクセスできます。まず、Git を netrc ヘルパースクリプトに誘導します。
$ git config --global credential.helper /usr/share/git/credential/netrc/git-credential-netrc.perl
次に、.netrc ファイルを 作成 します。
~/.netrc
machine git-host login username password password
認証情報ヘルパーは gpg で暗号化されたファイル (~/.netrc.gpg) もサポートします。
デフォルトプロトコル
上述のように SSH で多重接続することで、Git over SSH の方が HTTPS よりも高速になります。また、(AUR など) サーバーによっては SSH を介して push することもできます。例えば、以下の設定をすると AUR でホストされているリポジトリで Git over SSH を設定します。
~/.gitconfig
[url "ssh://aur@aur.archlinux.org/"] insteadOf = https://aur.archlinux.org/ insteadOf = http://aur.archlinux.org/ insteadOf = git://aur.archlinux.org/
Bash 補完
Bash の補完を有効にするには、Bash のスタートアップファイルで /usr/share/git/completion/git-completion.bash を source してください。もしくは、bash-completion をインストールしてください。
Git プロンプト
Git パッケージにはプロンプトスクリプトが付属しています。これを有効にするには、/usr/share/git/completion/git-prompt.sh をソースし、%s パラメータを使用してカスタムプロンプトを設定します。
- Bash の場合:
PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' - zsh の場合:
setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
Git リポジトリのディレクトリに変更すると、プロンプトが変化してブランチ名が表示されます。対応する環境変数を設定することで、追加の詳細がプロンプトに表示されるように設定できます。
| シェル変数 | 情報 |
|---|---|
| GIT_PS1_SHOWDIRTYSTATE | ステージ済みの場合は +、未ステージの場合は * |
| GIT_PS1_SHOWSTASHSTATE | スタッシュが存在する場合は $ |
| GIT_PS1_SHOWUNTRACKEDFILES | 追跡されていないファイルが存在する場合は % |
| GIT_PS1_SHOWUPSTREAM | 上流からの進み・戻り・分岐 (<,>,<>) |
| GIT_PS1_STATESEPARATOR | ブランチ名と状態記号の間の区切り文字 |
| GIT_PS1_DESCRIBE_STYLE | HEAD が切り離されている場合、タグまたはブランチに関連するコミットを表示します |
| GIT_PS1_SHOWCOLORHINTS | カラーで表示する |
環境変数の完全なドキュメントは、スクリプトのコメントで参照できます。
もしくは、bash-git-promptAUR や gittifyAUR など AUR にある git シェルプロンプトのカスタマイズパッケージを利用することもできます。
ビジュアル表現
作業量を把握するため:
$ git diff --stat
git log をフォーク表現:
$ git log --graph --oneline --decorate
git log グラフのエイリアス (つまり git graph は装飾されたバージョンを表示する):
$ git config --global alias.graph 'log --graph --oneline --decorate'
コミットのヒント
前のコミットにリセット (非常に危険、指定したコミットまですべて消去されます):
$ git reset --hard HEAD^
リポジトリのアドレスが変更された場合、そのリモートロケーションを更新する必要があります:
$ git remote set-url origin git@address:user/repo.git
あるいは、.git/config を編集して新しい場所を指定します。
Signed-off-by line append (プロジェクトによっては必要な、名前と電子メールの署名がコミットに追加されます):
$ git commit -s
Signed-off-by は自動的にパッチに追加されます (git format-patch commit を使用する場合):
$ git config --local format.signoff true
変更されたファイルの特定の部分をコミットします。これは、多数の変更があり、複数のコミットに分けたほうがよい場合に有用です。
$ git add -p
コミットへの署名
Git では、コミットやタグに GnuPG を使って署名することができます。Signing Your Work を参照してください。
Git が自動的にコミットに署名するように設定するには:
$ git config --global commit.gpgSign true
マスター以外のブランチで作業
ときに、メンテナからブランチで作業するように要求されることがあります。使われるブランチの名前は devel や testing などが一般的です。まずはリポジトリを複製します。
master 以外のブランチを開くには (git clone で master ブランチしか表示されない場合、git branch -a で他のブランチを表示できます):
$ git checkout -b branch origin/branch
通常通り編集を行ってください。ただし以下のコマンドを使ってリポジトリツリーを同期させてください:
$ git pull --all $ git push --all
メーリングリストにパッチを送信
メーリングリストに直接パッチを送る場合、次のパッケージをインストールする必要があります: perl-authen-sasl, perl-net-smtp-ssl, perl-mime-tools
ユーザー名とメールアドレスを設定したか確認してください、基本設定 を参照
メールアドレスを設定:
$ git config --global sendemail.smtpserver smtp.gmail.com $ git config --global sendemail.smtpserverport 587 $ git config --global sendemail.smtpencryption tls $ git config --global sendemail.smtpuser foobar@gmail.com
これでメーリングリストにパッチを送信することができます (OpenEmbedded:How to submit a patch to OpenEmbedded#Sending patches を参照):
$ git add filename $ git commit -s $ git send-email --to=openembedded-core@lists.openembedded.org --confirm=always -M -1
大規模な git リポジトリの操作
大規模なリモートリポジトリを操作する場合、大量のデータをフェッチする必要があります。次の例では、Linux カーネルを使用して、そのようなコードベースを操作する方法を示しています。
リポジトリ全体を取得する
最も簡単な解決策は、リポジトリ全体を取得することです。
$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
git pull でリポジトリを更新できます。
リポジトリの部分的な取得
ローカルリポジトリをオリジンのより小さなサブセットに制限するには、たとえば v4.14 以降でバグを二分するために、浅いクローンを使用します。
$ git clone --shallow-exclude v4.13 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
v4.14 以降は入手できますが、v4.13 以前は入手できません。
すべての履歴を無視して、最新のスナップショットのみが必要な場合。(tarball が利用可能で、それで十分な場合は、それを選択してください。git リポジトリからダウンロードするには、より多くの帯域幅が必要です。) 次の方法で取得できます。
$ git clone --depth 1 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
次の2つの例に示すように、後で古いコミットを取得できます。
$ git fetch --tags --shallow-exclude v4.1 $ git fetch --tags --shallow-since 2016-01-01
他のブランチを取得する
上記の例では、ローカル リポジトリはメインラインカーネル、つまり 最新の開発が行われた カーネルのみを追跡します。たとえば、最新の 4.14 ブランチなど、最新の LTS が必要な場合、次の方法で取得できます。
$ git remote set-branches --add origin linux-4.17.y $ git fetch $ git branch --track linux-4.17.y origin/linux-4.17.y
最後の行は必須ではありませんが、おそらく必要でしょう。 (必要なブランチの名前を知るために、一般的なルールはありません。gitweb のインターフェイスにある "ref" リンクを見れば、推測することができます。)
linux-4.17.y のスナップショットについては、次のようにします。
$ git checkout -b linux-4.17.y
または、別のディレクトリに展開するには、
$ mkdir /path/to/src-4.17; cd /path/to /src-4.17 $ git clone --no-local --depth 1 -b linux-4.17.y ../linux-stable
いつものように、git pull を実行してスナップショットを更新します。
代替案
Virtual File System for Git (VFS for Git) は、ローカルのリポジトリがなくても git のリポジトリにアクセスできるようにするものです。(この Microsoft ブログ や Wikipedia article を参照してください。)
これは、gvfs と scalar を含む git の Microsoft のフォークである git-vfsAUR で利用可能です。
機密情報のフィルタリング
時には、ソフトウェアが平文のパスワードを設定ファイルに保存し、キーリングに接続するのとは対照的にすることがあります。このような場合、git clean-filters は機密情報を誤ってコミットしてしまうのを防ぐために便利です。たとえば、次のファイルでは "some-dotfile" というファイルにフィルタを割り当てています。
.gitattributes
some-dotfile filter=remove-pass
"some-dotfile" というファイルが git にチェックインされると、git はチェックイン前にこのファイルに対して "remove-pass" というフィルタを実行します。このフィルターは、git-configuration ファイルで定義しておく必要があります。
.git/config
[filter "remove-pass"] clean = "sed -e 's/^password=.*/#password=TODO/'"
HTML ヘルプファイル
git-htmldocsAUR をインストールすることで、git help のドキュメントを HTML 形式で利用することもできます。インストール後、HTML ドキュメントには -w フラグを付けてアクセスすることができます。例えば
$ git help -w merge
git config オプションを設定すると、デフォルトで HTML ドキュメントを読み込むことができます。
$ git config --global help.format html
拡張機能
- gitflow-avh — Vincent Driessen の分岐モデル で git を拡張します。AVH Edition はより多くの機能を追加します。
- git-extras — git 用のいくつかのユーティリティ (リポジトリの概要、repl、変更ログの人数、作成者のコミット率など)
- https://github.com/tj/git-extras || git-extrasAUR - oh-my-zsh を使用している場合、git-extras プラグイン を有効にして下さい。
- gitmoji-cli — A gitmoji コミットメッセージで gitmojis を使用するためのインタラクティブな NodeJS クライアント。