kledgeb UbuntuやLinuxの最新情報を紹介

Ubuntu Git その352 - 差分適用時の空白文字の警告表示を制御する・差分適用時に空白文字を自動的に修正する(git rebase)

差分適用時の空白文字の警告表示を制御する・差分適用時に空白文字を自動的に修正する

  差分適用時の空白文字の警告表示を制御して、「リベース」を行います。
  また、差分適用時に空白文字を自動的に修正して、「リベース」を行います。

  空白文字の警告

    行末に空白文字が存在する場合や、行頭にスペースに続くタブ文字が存在する場合は、 それらの警告を表示します。

  空白文字の自動修正

    差分を適用時、警告に該当する空白文字を修正して、適用を行います。

  注意

    インタラクティブモード(--interactive)では、利用できません。

コマンドのオプションについて

  空白文字の警告表示の制御や修正は、以下のオプションを指定します。

オプション
--whitespace=

  オプションの値には、以下のいずれかの値を指定します。

  1.nowarn

    空白文字の警告を表示しません。
    差分の適用は行われます。

  2.warn

    空白文字の警告を表示します。
    表示される警告数は、最初の5つです。
    差分の適用は行われます。

  3.fix

    空白文字の警告を表示し、警告に該当する空白文字を修正して、差分の適用を行います。
    表示される警告数は、最初の5つです。

  4.error

    空白文字の警告を表示し、リベースを中断します。
    表示される警告数は、最初の5つです。

    この時、差分の適用は行われません。

  5.error-all

    空白文字の警告を表示し、リベースを中断します。
    全ての警告が表示されます。

    この時、差分の適用は行われません。

例で使用するリポジトリー

  ここでは例として、以下のリポジトリーを使用します。

  1.ブランチの確認

    現在のブランチ構成を確認すると、以下のようになっています。
    現在のブランチは、「fix」ブランチであることが分かります。
    同様に、「HEAD」は「fix」ブランチを指していることが分かります。


    ここでは例として、「fix」ブランチを「master」ブランチにリベースし、「mastsr」ブランチに「fix」ブランチの変更内容を結合します。

  2.ブランチの構成

    現在のブランチの構成を図にすると、以下のようになっています。


    「fix」ブランチを「master」ブランチにリベースするため、リベース対象の「コミットオブジェクト」は、以下のようになります。

  • Commit4
  • Commit5

  4.masterブランチのmaster.txtファイルの中身

    「master」ブランチの「master.txt」ファイルに着目します。
    「master.txt」ファイルの中身は、以下のようになっています。  


  5.fixブランチのmaster.txtファイルの中身

    「fix」ブランチの「master.txt」ファイルに着目します。
    「master.txt」ファイルの中身は、以下のようになっています。  



    グレーの「・」は、半角スペースを表しています。
    グレーの「→」は、タブ文字を表しています。

1.nowarnの指定例

  「nowarn」の指定例です。

  1-1.コマンドの実行

    「端末」から、以下のコマンドを実行します。
    コマンドの詳細は、「ファイルの変更内容を異なるブランチに結合するコマンドの説明」を参考にしてください。

    ポイントは、赤字の箇所です。

git rebase --verbose --whitespace=nowarn master


  1-2.コマンドの実行結果

    以下のように、リベース結果が表示されます。

ubuntu@ubuntu-vb-1504:~/git/myCloneProject$ git rebase --verbose --whitespace=nowarn master
Changes from 2537d065f4f34d5c75093e1091a0ddcd4681c5fe to fb0ee9b536a5ae0cb745cacdf1224e7b5d872cc0:
 master.txt | 1 +
 new.txt    | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 new.txt
First, rewinding head to replay your work on top of it...
Applying: fix
Applying: fix
Using index info to reconstruct a base tree...
M    master.txt
Falling back to patching base and 3-way merge...
Auto-merging master.txt
CONFLICT (content): Merge conflict in master.txt
Failed to merge in the changes.
Patch failed at 0002 fix
The copy of the patch that failed is found in:
   /home/ubuntu/git/myCloneProject/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

    空白文字の警告は表示されません。

2.warnの指定例

  「warn」の指定例です。

  2-1.コマンドの実行

    「端末」から、以下のコマンドを実行します。
    コマンドの詳細は、「ファイルの変更内容を異なるブランチに結合するコマンドの説明」を参考にしてください。

    ポイントは、赤字の箇所です。

git rebase --verbose --whitespace=warn master


  2-2.コマンドの実行結果

    以下のように、リベース結果が表示されます。

ubuntu@ubuntu-vb-1504:~/git/myCloneProject$ git rebase --verbose --whitespace=warn master
Changes from 2537d065f4f34d5c75093e1091a0ddcd4681c5fe to fb0ee9b536a5ae0cb745cacdf1224e7b5d872cc0:
 master.txt | 1 +
 new.txt    | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 new.txt
First, rewinding head to replay your work on top of it...
Applying: fix
Applying: fix
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:8: trailing whitespace.
master2 
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:9: space before tab in indent.
     master3
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:10: space before tab in indent.
     master4
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:11: space before tab in indent.
         master5
warning: 4 lines add whitespace errors.
Using index info to reconstruct a base tree...
M    master.txt
<stdin>:8: trailing whitespace.
master2 
<stdin>:9: space before tab in indent.
     master3
<stdin>:10: space before tab in indent.
     master4
<stdin>:11: space before tab in indent.
         master5
warning: 4 lines add whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging master.txt
CONFLICT (content): Merge conflict in master.txt
Failed to merge in the changes.
Patch failed at 0002 fix
The copy of the patch that failed is found in:
   /home/ubuntu/git/myCloneProject/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

    空白文字の警告は表示されます。
    空白文字の警告を抽出すると、以下のようになります。

/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:8: trailing whitespace.
master2 
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:9: space before tab in indent.
     master3
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:10: space before tab in indent.
     master4
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:11: space before tab in indent.
         master5
warning: 4 lines add whitespace errors.
Using index info to reconstruct a base tree...
M    master.txt
<stdin>:8: trailing whitespace.
master2 
<stdin>:9: space before tab in indent.
     master3
<stdin>:10: space before tab in indent.
     master4
<stdin>:11: space before tab in indent.
         master5
warning: 4 lines add whitespace errors.

3.warnの指定例

  「warn」の指定例です。

  3-1.コマンドの実行

    「端末」から、以下のコマンドを実行します。
    コマンドの詳細は、「ファイルの変更内容を異なるブランチに結合するコマンドの説明」を参考にしてください。

    ポイントは、赤字の箇所です。

git rebase --verbose --whitespace=warn master


  3-2.コマンドの実行結果

    以下のように、リベース結果が表示されます。

ubuntu@ubuntu-vb-1504:~/git/myCloneProject$ git rebase --verbose --whitespace=fix master
Changes from 2537d065f4f34d5c75093e1091a0ddcd4681c5fe to fb0ee9b536a5ae0cb745cacdf1224e7b5d872cc0:
 master.txt | 1 +
 new.txt    | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 new.txt
First, rewinding head to replay your work on top of it...
Applying: fix
Applying: fix
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:8: trailing whitespace.
master2 
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:9: space before tab in indent.
     master3
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:10: space before tab in indent.
     master4
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:11: space before tab in indent.
         master5
warning: 4 lines add whitespace errors.
Using index info to reconstruct a base tree...
M    master.txt
<stdin>:8: trailing whitespace.
master2 
<stdin>:9: space before tab in indent.
     master3
<stdin>:10: space before tab in indent.
     master4
<stdin>:11: space before tab in indent.
         master5
warning: 4 lines applied after fixing whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging master.txt
CONFLICT (content): Merge conflict in master.txt
Failed to merge in the changes.
Patch failed at 0002 fix
The copy of the patch that failed is found in:
   /home/ubuntu/git/myCloneProject/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

    空白文字の警告は表示されます。
    空白文字の警告を抽出すると、以下のようになります。

/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:8: trailing whitespace.
master2 
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:9: space before tab in indent.
     master3
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:10: space before tab in indent.
     master4
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:11: space before tab in indent.
         master5
warning: 4 lines add whitespace errors.
Using index info to reconstruct a base tree...
M    master.txt
<stdin>:8: trailing whitespace.
master2 
<stdin>:9: space before tab in indent.
     master3
<stdin>:10: space before tab in indent.
     master4
<stdin>:11: space before tab in indent.
         master5
warning: 4 lines applied after fixing whitespace errors.

  3-3.master.txtファイルの中身

    「マージコンフリクト」が発生した「master.txt」ファイルの中身を見ると、以下のようになっています。


    空白文字の警告が発生した箇所が修正されています。

4.errorの指定例

  「error」の指定例です。

  4-1.コマンドの実行

    「端末」から、以下のコマンドを実行します。
    コマンドの詳細は、「ファイルの変更内容を異なるブランチに結合するコマンドの説明」を参考にしてください。

    ポイントは、赤字の箇所です。

git rebase --verbose --whitespace=error master


  4-2.コマンドの実行結果

    以下のように、リベース結果が表示されます。

ubuntu@ubuntu-vb-1504:~/git/myCloneProject$ git rebase --verbose --whitespace=error master
Changes from 2537d065f4f34d5c75093e1091a0ddcd4681c5fe to fb0ee9b536a5ae0cb745cacdf1224e7b5d872cc0:
 master.txt | 1 +
 new.txt    | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 new.txt
First, rewinding head to replay your work on top of it...
Applying: fix
Applying: fix
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:8: trailing whitespace.
master2 
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:9: space before tab in indent.
     master3
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:10: space before tab in indent.
     master4
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:11: space before tab in indent.
         master5
fatal: 4 lines add whitespace errors.
Repository lacks necessary blobs to fall back on 3-way merge.
Cannot fall back to three-way merge.
Patch failed at 0002 fix
The copy of the patch that failed is found in:
   /home/ubuntu/git/myCloneProject/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

    空白文字の警告は表示されます。
    空白文字の警告を抽出すると、以下のようになります。

/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:8: trailing whitespace.
master2 
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:9: space before tab in indent.
     master3
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:10: space before tab in indent.
     master4
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:11: space before tab in indent.
         master5
fatal: 4 lines add whitespace errors.

  4-3.master.txtファイルの中身

    「マージコンフリクト」が発生した「master.txt」ファイルの中身を見ると、以下のようになっています。


    差分適用前の状態で、リベースが中断されています。

5.error-all

  「error-all」の指定例です。

  5-1.コマンドの実行

    「端末」から、以下のコマンドを実行します。
    コマンドの詳細は、「ファイルの変更内容を異なるブランチに結合するコマンドの説明」を参考にしてください。

    ポイントは、赤字の箇所です。

git rebase --verbose --whitespace=error-all master


  5-2.コマンドの実行結果

    以下のように、リベース結果が表示されます。

ubuntu@ubuntu-vb-1504:~/git/myCloneProject$ git rebase --verbose --whitespace=error-all master
Changes from 2537d065f4f34d5c75093e1091a0ddcd4681c5fe to fb0ee9b536a5ae0cb745cacdf1224e7b5d872cc0:
 master.txt | 1 +
 new.txt    | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 new.txt
First, rewinding head to replay your work on top of it...
Applying: fix
Applying: fix
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:8: trailing whitespace.
master2 
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:9: space before tab in indent.
     master3
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:10: space before tab in indent.
     master4
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:11: space before tab in indent.
         master5
fatal: 4 lines add whitespace errors.
Repository lacks necessary blobs to fall back on 3-way merge.
Cannot fall back to three-way merge.
Patch failed at 0002 fix
The copy of the patch that failed is found in:
   /home/ubuntu/git/myCloneProject/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

    空白文字の警告は表示されます。
    空白文字の警告を抽出すると、以下のようになります。

/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:8: trailing whitespace.
master2 
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:9: space before tab in indent.
     master3
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:10: space before tab in indent.
     master4
/home/ubuntu/git/myCloneProject/.git/rebase-apply/patch:11: space before tab in indent.
         master5
fatal: 4 lines add whitespace errors.

  5-3.master.txtファイルの中身

    「マージコンフリクト」が発生した「master.txt」ファイルの中身を見ると、以下のようになっています。


    差分適用前の状態で、リベースが中断されています。


Git
スポンサー
コメント
コメントポリシー
コメントをする前に UbuntuのCode of Conduct(CoC/行動規範) を確認し、CoCに沿ったコメントをお願いします。
コメントの使い方は、コメントの使い方を参照してください。
同一カテゴリーの記事
SNS
人気の記事
  • Ubuntu 22.04 その120 - UbuntuのブートローダーをBoot Repairで修復するには・Ubuntuが起動しないトラブルを解決
    UbuntuのブートローダーをBoot Repairで修復するには 「Boot Repair」はOSのブートローダーに起因するOSが起動しない問題を簡単に解決してくれるアプリです。
  • Ubuntu 22.04 その95 - ディスプレイサーバーを切り替えるには・XorgとWayland
    ディスプレイサーバーを切り替えるには 「Ubuntu」はデフォルトで2種類のディスプレイサーバーを提供しています。
  • Ubuntu 24.04 その70 - Ubuntu 24.04.4 LTS のリリーススケジュール
    Ubuntu 24.04.4 LTS のリリーススケジュール Ubuntu 24.04.4 LTS のリリーススケジュールを紹介します。
  • Ubuntu 22.04 その79 - 画面ロックの有効・無効を設定するには・画面ロック時の設定をカスタマイズするには
    画面ロックの有効・無効を設定するには 一定時間ユーザーによる操作がない時に、自動的に画面をロックしパスワードで保護したり、画面をブランク状態にできます。
  • Ubuntu 26.04 その9 - Ubuntu Desktop 26.04 LTS の開発方針・プリインストールアプリの変更やソフトウェア管理の一元化など
    Ubuntu Desktop 26.04 LTS の開発方針 2025年11月26日、Ubuntu Desktop 26.04 LTS の開発方針がアナウンスされました。
  • Ubuntu nano その5 - 文字列を検索する
    文字列を検索する(Where Is)   文字列の検索は、部分一致と正規表現による検索が可能です。 検索の開始始点   現在カーソルのある位置から検索を行います。   もし、テキストの最後まで検索して文字が見つからない場合、   nanoはテキストの先頭から検索...
  • Ubuntu 22.04 その98 - 入力ソースとキーボートレイアウトと日本語入力のカスタマイズ
    入力ソースとキーボートレイアウトと日本語入力 「Ubuntu」ではユーザーが利用しているキーボードレイアウトや日本語入力のカスタマイズが可能です。
  • VirtualBox その125 - ゲストOSのUbuntuにLinux Guest Additionsをインストールするには
    ゲストOSのUbuntuにLinux Guest Additionsをインストールするには 仮想マシンにインストールしたゲストOSの「Ubuntu」に、「Linux Guest Additions」をインストールする方法です。
  • Ubuntu 22.04 LTSのインストール その5 - UEFI環境でパーティションの作成と構成 〜 ブートローダーのインストール先の選択
    UEFI環境でパーティションの作成と構成を行う UEFI環境でパーティションの作成と構成を行います。
  • Ubuntu 22.04 その99 - 日本語入力(Mozc)の設定をカスタマイズして作業効率を上げよう
    日本語入力(Mozc)の設定をカスタマイズするには 「Ubuntu」では日本語入力に「Mozc」を採用しています。
記事のピックアップ
オプション