<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>「GitGraph」タグの記事一覧Python Tech</title>
	<atom:link href="https://tech.nkhn37.net/tag/gitgraph/feed/" rel="self" type="application/rss+xml" />
	<link>https://tech.nkhn37.net</link>
	<description>Python学習サイト</description>
	<lastBuildDate>Sun, 11 Jan 2026 05:29:03 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://tech.nkhn37.net/wp-content/uploads/2021/01/cropped-lion-normal-clear-1-32x32.png</url>
	<title>「GitGraph」タグの記事一覧Python Tech</title>
	<link>https://tech.nkhn37.net</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>VSCodeでGitのrebaseを実施する方法</title>
		<link>https://tech.nkhn37.net/git-rebase-vscode-basic/</link>
					<comments>https://tech.nkhn37.net/git-rebase-vscode-basic/#respond</comments>
		
		<dc:creator><![CDATA[naoki-hn]]></dc:creator>
		<pubDate>Sat, 12 Nov 2022 20:00:00 +0000</pubDate>
				<category><![CDATA[VS Code]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[GitGraph]]></category>
		<category><![CDATA[GitLens]]></category>
		<category><![CDATA[rebase]]></category>
		<guid isPermaLink="false">https://tech.nkhn37.net/?p=5681</guid>

					<description><![CDATA[VSCodeでGitのrebaseを実施する方法について解説します。 Gitのrebase rebaseとは Gitは、プログラムソース等のバージョン管理ソフトウェアです。rebaseとは、Gitで提供されるコマンドの一 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><span class="marker"><strong>VSCodeでGitのrebaseを実施する方法</strong></span>について解説します。</p>



<h2 class="wp-block-heading jinr-heading d--bold">Gitのrebase</h2>



<h3 class="wp-block-heading jinr-heading d--bold">rebaseとは</h3>



<p class="wp-block-paragraph">Gitは、プログラムソース等のバージョン管理ソフトウェアです。<span class="marker"><strong>rebase</strong></span>とは、Gitで提供されるコマンドの一種です。</p>



<p class="wp-block-paragraph">似たコマンドとして開発ブランチをまとめるmergeというコマンドがありますが、こちらは感覚的にも理解しやすいのに対して、このrebaseというコマンドは取り扱いが少し難しいコマンドです。</p>



<p class="wp-block-paragraph">rebaseコマンドを一言で表すと「コミットをつなげなおしたり、ひとまとめにしたり、コミットメッセージを修正したりして、ログを綺麗にする」コマンドです。</p>



<p class="wp-block-paragraph">本記事では、コードエディタのVSCodeを使いつつ、rebaseコマンドを実行して使う方法について、いくつかの主要な使い方に絞って図を用いながら紹介していきます。</p>



<h2 class="wp-block-heading jinr-heading d--bold">VSCodeを用いてGitのrebaseを実行する方法</h2>



<p class="wp-block-paragraph">ここからは、コードエディタである<span class="marker"><strong>VSCodeを使ってGitのrebaseを実行する方法</strong></span>を紹介します。</p>



<p class="wp-block-paragraph">前提として、VSCodeの拡張機能である<span class="marker"><strong>GitLens</strong></span>と<span class="marker"><strong>GitGraph</strong></span>を使用しています。VSCodeの拡張機能としてインストールしておいてください。インストール方法が分からない方は、本記事内に<a href="https://tech.nkhn37.net/?p=5681&amp;preview=true#Git">こちら</a>にインストール方法の参考を設けていますので、確認してインストールしてください。</p>



<h3 class="wp-block-heading jinr-heading d--bold">rebaseでのよくある主要な使い方</h3>



<p class="wp-block-paragraph">rebaseはいくつかの使用ケースが考えられるかと思いますが、よくある主要な使い方だと思われる以下の３種類の方法について、概要図なども交えて紹介していきます。</p>



<ol class="wp-block-list jinr-list">
<li>開発コミットをつなげなおす</li>



<li>複数コミットを一つにまとめる</li>



<li>コミットメッセージを修正する</li>
</ol>



<h4 class="wp-block-heading jinr-heading d--bold">開発コミットをつなげなおす</h4>



<p class="wp-block-paragraph">一つ目の例として、開発コミットをつなげなおす例を紹介します。具体的には、以下の図でブランチAとブランチBのように複数のブランチで開発コミットしていた時に、ブランチAの後ろにブランチBをつなげなおすことを考えてみたいと思います。</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="981" height="772" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-86.png" alt="rebase 開発コミットをつなげなおす" class="wp-image-5746" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-86.png 981w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-86-300x236.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-86-768x604.png 768w" sizes="(max-width: 981px) 100vw, 981px" /></figure>



<p class="wp-block-paragraph">上記の例は、startの位置でブランチAとブランチBが作成されてそれぞれで開発を進めた場合を示しています。</p>



<p class="wp-block-paragraph">では、具体的にVSCode上でどのような手順を実施するか見ていきましょう。以下が実際に上記のような状況でのGitGraphのコミットグラフです。このコミットグラフの状態からブランチAの後ろにブランチBをつなげる手順を見ていきましょう。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="290" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-64-1024x290.png" alt="rebase 開発コミットをつなげなおす" class="wp-image-5708" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-64-1024x290.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-64-300x85.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-64-768x218.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-64.png 1097w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">まず、ブランチBがチェックアウトされている状態で、ベースとなるブランチA上で右クリックし、「Rebase current branch on this commit&#8230;」をクリックします。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="365" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-67-1024x365.png" alt="rebase 開発コミットをつなげなおす" class="wp-image-5711" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-67-1024x365.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-67-300x107.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-67-768x274.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-67.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">以下のようなダイアログが出るので、「Launch Interactive Rebase in new Terminal」にチェックを入れて「Yes, rebase」をクリックします。</p>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img decoding="async" width="934" height="231" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-68.png" alt="rebase 開発コミットをつなげなおす" class="wp-image-5712" style="width:467px;height:116px" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-68.png 934w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-68-300x74.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-68-768x190.png 768w" sizes="(max-width: 934px) 100vw, 934px" /></figure>
</div>


<p class="wp-block-paragraph">すると以下のようなGitLens Interactive Rebase画面が表示されます。各行がコミットを表していてプルダウンでいくつかの処理が選べます。「pick」は何もせずそのまま使うという意味で、今回はコミット自体には変更等加えずに、つなぎ変えるだけですのでpickを選んだ状態で「START REBASE」をクリックします。もしくは「Ctrl + Enter」でも実行できます。なお、処理をやめたいときは「ABORT」をクリックしてください。</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" width="1000" height="566" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-70.png" alt="rebase 開発コミットをつなげなおす" class="wp-image-5714" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-70.png 1000w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-70-300x170.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-70-768x435.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-70-320x180.png 320w" sizes="(max-width: 1000px) 100vw, 1000px" /></figure>
</div>


<p class="wp-block-paragraph">Rebaseを実行するとVSCodeのターミナルで以下のような表示がされます。「git rebase」というのがコマンドが実行されて、成功していることが分かります。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git rebase --interactive c219f6ef4154eb71753828a641795630a38384e2

Successfully rebased and updated refs/heads/branch-B.</pre>



<p class="wp-block-paragraph">GitGraph上で更新ボタンを押すとグラフが更新されます。</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="572" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-85-1024x572.png" alt="rebase 開発コミットをつなげなおす" class="wp-image-5743" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-85-1024x572.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-85-300x167.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-85-768x429.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-85-320x180.png 320w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-85.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">上記のように、Aの後ろにつなぎなおされて一直線のきれいなコミットグラフになったことが分かります。</p>



<h4 class="wp-block-heading jinr-heading d--bold">複数コミットを一つにまとめる</h4>



<p class="wp-block-paragraph">次に、複数コミットを一つにまとめる例を紹介します。コミットは開発にそって適宜実施していくわけですが、後から見ると複数のコミットをひとまとめのコミットにしておいた方が変更内容が理解しやすく、すっきりとするような場合がよくあります。</p>



<p class="wp-block-paragraph">このような際には、rebaseを使って以下の図のようなイメージで複数コミットを一つにまとめることができます。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="370" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-62-1024x370.png" alt="rebase 複数コミットを一つにまとめる" class="wp-image-5704" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-62-1024x370.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-62-300x108.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-62-768x277.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-62.png 1260w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">上記は、もともとa~dまであったコミットをまとめてeという一つのコミットにまとめているような例を示しています。</p>



<p class="wp-block-paragraph">では、具体的にVSCode上でどのような手順を実施するか見ていきましょう。以下が実際に上記のような状況でのGitGraphのコミットグラフです。このコミットグラフで、ファイル作成～変更1, 2, 3のコミットを一つにまとめてみましょう。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="287" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-72-1024x287.png" alt="rebase 複数コミットを一つにまとめる" class="wp-image-5717" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-72-1024x287.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-72-300x84.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-72-768x215.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-72.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">まず、ブランチAがチェックアウトされている状態で、変更したい範囲の一つ前のコミットを右クリックし、「Rebase current branch on this commit&#8230;」をクリックします。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="393" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-73-1024x393.png" alt="rebase 複数コミットを一つにまとめる" class="wp-image-5718" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-73-1024x393.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-73-300x115.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-73-768x294.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-73.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">以下のようなダイアログが出るので、「Launch Interactive Rebase in new Terminal」にチェックを入れて「Yes, rebase」をクリックします。</p>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img decoding="async" width="931" height="235" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-74.png" alt="rebase 複数コミットを一つにまとめる" class="wp-image-5719" style="width:466px;height:118px" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-74.png 931w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-74-300x76.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-74-768x194.png 768w" sizes="(max-width: 931px) 100vw, 931px" /></figure>
</div>


<p class="wp-block-paragraph">すると以下のようなGitLens Interactive Rebase画面が表示されます。各行がコミットを表していてプルダウンでいくつかの処理が選べます。今回は、コミットを統合するので統合するコミットを「squash」に変更して、「START REBASE」をクリックします。もしくは「Ctrl + Enter」でも実行できます。なお、処理をやめたいときは「ABORT」をクリックしてください。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="640" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-75-1024x640.png" alt="rebase 複数コミットを一つにまとめる" class="wp-image-5720" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-75-1024x640.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-75-300x188.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-75-768x480.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-75.png 1102w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">すると、GITで設定されているエディタが起動し以下のような画面になります。この例ではVSCodeが起動している例です。この画面ではコミットメッセージの変更をすることができ、#から始まる行はコミットメッセージとしては無視されます。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="671" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-1024x671.jpg" alt="rebase 複数コミットを一つにまとめる" class="wp-image-5721" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-1024x671.jpg 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-300x197.jpg 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-768x503.jpg 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">今回は、一つにコミットをまとめたメッセージにしたいので以下のように変更して保存し、「×」で閉じると処理が継続します。</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="531" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-1-1024x531.jpg" alt="rebase 複数コミットを一つにまとめる" class="wp-image-5722" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-1-1024x531.jpg 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-1-300x155.jpg 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-1-768x398.jpg 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-1.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">Rebaseを実行するとVSCodeのターミナルで以下のような表示がされます。「git rebase」というのがコマンドが実行されて、成功していることが分かります。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git rebase --interactive 8f9c37b185f75ae5944cc05ea607290e3b93b14f

[detached HEAD 1e405dd] branch-A: ファイル作成&amp;変更
 Date: Sun Nov 13 09:43:39 2022 +0900
 1 file changed, 3 insertions(+)
 create mode 100644 testA.py
Successfully rebased and updated refs/heads/branch-A.</pre>



<p class="wp-block-paragraph">GitGraph上で更新ボタンを押すとグラフが更新されます。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="508" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-1024x508.png" alt="rebase 複数コミットを一つにまとめる" class="wp-image-5723" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-1024x508.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-300x149.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76-768x381.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-76.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">上記のように、複数あったコミットが一つのコミットにまとめられていることが分かるかと思います。</p>



<h4 class="wp-block-heading jinr-heading d--bold">コミットメッセージを修正する</h4>



<p class="wp-block-paragraph">Gitでコミットをしていると、たまにコミットメッセージを間違えたり、書くべき事項が足りなかったりといったケースがよく発生します。</p>



<p class="wp-block-paragraph">このような際には、rebaseを使って以下の図のようなイメージでコミットメッセージを修正することができます。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="391" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-77-1024x391.png" alt="rebase コミットメッセージを修正する" class="wp-image-5724" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-77-1024x391.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-77-300x114.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-77-768x293.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-77.png 1201w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">上記の例は、cの部分のコミットメッセージで変換ミスをしてしまった場合を示しています。</p>



<p class="wp-block-paragraph">では、具体的にVSCode上でどのような手順を実施するか見ていきましょう。以下が実際に上記のような状況でのGitGraphのコミットグラフです。このコミットグラフの状態からコミットメッセージを修正する手順を見ていきましょう。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="288" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-78-1024x288.png" alt="rebase コミットメッセージを修正する" class="wp-image-5725" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-78-1024x288.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-78-300x84.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-78-768x216.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-78.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">まず、ブランチAがチェックアウトされている状態で、変更したい範囲よりも前のコミットを右クリックし、「Rebase current branch on this commit&#8230;」をクリックします。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="407" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-79-1024x407.png" alt="rebase コミットメッセージを修正する" class="wp-image-5726" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-79-1024x407.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-79-300x119.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-79-768x305.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-79.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">以下のようなダイアログが出るので、「Launch Interactive Rebase in new Terminal」にチェックを入れて「Yes, rebase」をクリックします。</p>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img decoding="async" width="927" height="239" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-80.png" alt="rebase コミットメッセージを修正する" class="wp-image-5727" style="width:464px;height:120px" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-80.png 927w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-80-300x77.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-80-768x198.png 768w" sizes="(max-width: 927px) 100vw, 927px" /></figure>
</div>


<p class="wp-block-paragraph">すると以下のようなGitLens Interactive Rebase画面が表示されます。各行がコミットを表していてプルダウンでいくつかの処理が選べます。今回は、コミットメッセージを修正する対象のコミットを「reword」に変更して、「START REBASE」をクリックします。もしくは「Ctrl + Enter」でも実行できます。なお、処理をやめたいときは「ABORT」をクリックしてください。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="669" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-81-1024x669.png" alt="rebase コミットメッセージを修正する" class="wp-image-5728" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-81-1024x669.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-81-300x196.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-81-768x501.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-81.png 1092w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">すると、GITで設定されているエディタが起動し以下のような画面になります。この例ではVSCodeが起動している例です。この画面ではコミットメッセージの変更をすることができ、#から始まる行はコミットメッセージとしては無視されます。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="540" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-82-1024x540.jpg" alt="rebase コミットメッセージを修正する" class="wp-image-5729" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-82-1024x540.jpg 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-82-300x158.jpg 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-82-768x405.jpg 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-82.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">今回は、rewordに設定したコミットメッセージが表示されます。コミットメッセージを修正して保存し、「×」で閉じると処理が継続します。今回の例ではrewordに設定したのが一つのコミットでしたが、複数の場合は順次同様に変更します。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="553" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-82-1-1024x553.jpg" alt="rebase コミットメッセージを修正する" class="wp-image-5730" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-82-1-1024x553.jpg 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-82-1-300x162.jpg 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-82-1-768x415.jpg 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-82-1.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">Rebaseを実行するとVSCodeのターミナルで以下のような表示がされます。「git rebase」というのがコマンドが実行されて、成功していることが分かります。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git rebase --interactive 6291c81b14f50c98978dbe4287cfc8571148644f

[detached HEAD 6755a18] branch-A: ファイル変更2
 Date: Sun Nov 13 10:47:00 2022 +0900
 1 file changed, 1 insertion(+)
Successfully rebased and updated refs/heads/branch-A.</pre>



<p class="wp-block-paragraph">GitGraph上で更新ボタンを押すとグラフが更新されます。</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="572" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-84-1024x572.png" alt="rebase コミットメッセージを修正する" class="wp-image-5742" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-84-1024x572.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-84-300x167.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-84-768x429.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-84-320x180.png 320w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-84.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">上記のように、誤っていたコミットメッセージが修正されたことが分かるかと思います。</p>



<h3 class="wp-block-heading jinr-heading d--bold">rebaseのその他の処理</h3>



<p class="wp-block-paragraph">rebaseで上記でも使用してきたpick、squash、reword等がありますが、他にもありますので表でまとめておこうと思います。今回は主要な処理に絞ってということで一部しか紹介しませんでした。必要に応じて各処理の方法を調べてもらえるとよいかと思います。</p>



<figure class="wp-block-table"><table><thead><tr><th>処理</th><th>内容</th></tr></thead><tbody><tr><td>pick</td><td>何もしないで選択する</td></tr><tr><td>reword</td><td>コミットメッセージをまとめて変更する</td></tr><tr><td>edit</td><td>過去のコミットを修正する（該当箇所でrebaseを一時停止する）</td></tr><tr><td>squash</td><td>過去のコミットを統合する（コミットメッセージを変更する場合）</td></tr><tr><td>fixup</td><td>過去のコミットを統合する（コミットメッセージの変更が不要な場合）</td></tr><tr><td>drop</td><td>過去のコミットを削除する</td></tr></tbody></table></figure>



<h3 class="wp-block-heading jinr-heading d--bold">mergeとrebaseの使い分け</h3>



<p class="wp-block-paragraph">mergeコマンドとrebaseコマンドの大きな違いは、「<span class="marker"><strong>既存のコミットに影響を与えるか否か</strong></span>」という点です。mergeコマンドを使うと、merge commitとして新しいコミットを作成するので既存のコミットに影響を与えることはありません。</p>



<p class="wp-block-paragraph">そのため、複数の開発メンバーにて、共同開発をしている環境で安易にrebaseしてしまうと他の人のコミットを勝手に作り直してしまうというようなことが発生してしまう可能性もあります。</p>



<p class="wp-block-paragraph">そのため、まだリモートリポジトリにpushしていない段階のローカルリポジトリ内でコミットの内容を修正するのにはrebaseを使うようにするとよいと思います。一方で、pushした後で他の人も見ている・ソースを修正しているような場合については、mergeを使用するようにしましょう。共同開発環境ではpull requestを通じて検証をしつつmergeするというのが一般的かと思います。</p>



<h2 class="wp-block-heading jinr-heading d--bold">【参考】Git拡張機能のインストール</h2>



<h3 class="wp-block-heading jinr-heading d--bold">GitGraphのインストール</h3>



<p class="wp-block-paragraph"><span class="marker"><strong>GitGraph</strong></span>は、Gitのコミットグラフをきれいに表示するためのVSCode拡張です。以下のように拡張タブからインストールしてください。</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="655" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-56-1024x655.png" alt="GitGraph" class="wp-image-5685" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-56-1024x655.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-56-300x192.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-56-768x492.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-56.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">インストールすると、ソース管理タブのところから以下のボタンを押すことでGitGraphによるコミットグラフを表示することができます。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="229" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-57-1024x229.png" alt="GitGraph" class="wp-image-5686" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-57-1024x229.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-57-300x67.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-57-768x172.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-57.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<h3 class="wp-block-heading jinr-heading d--bold">GitLensのインストール</h3>



<p class="wp-block-paragraph"><span class="marker"><strong>GitLens</strong></span>は、Gitの変更情報などをVSCode上で確認したりするのに非常に便利な拡張機能です。以下のように拡張タブからインストールしてください。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="695" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-58-1024x695.png" alt="GitLens" class="wp-image-5688" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-58-1024x695.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-58-300x203.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-58-768x521.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-58.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">GitLensを導入すると、ソースコード上にファイルの変更時刻や各行が最後に変更された際のコミットメッセージなどをソース上でも確認できるようになります。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="535" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-59-1024x535.jpg" alt="GitLens" class="wp-image-5689" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-59-1024x535.jpg 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-59-300x157.jpg 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-59-768x401.jpg 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-59.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">他にもgitの変更情報を以下のようにコミットメッセージと並べて見たりなど、色々とGitのコミット情報を確認してプログラミングを進めるのに便利な機能が提供されています。</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="440" src="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-59-1024x440.png" alt="GitLens" class="wp-image-5690" srcset="https://tech.nkhn37.net/wp-content/uploads/2022/11/image-59-1024x440.png 1024w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-59-300x129.png 300w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-59-768x330.png 768w, https://tech.nkhn37.net/wp-content/uploads/2022/11/image-59.png 1400w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p class="wp-block-paragraph">今回の記事では、上記で紹介している例のように「GitLens Interactive Rebase」ということでrebaseのコマンドをGUIでできる機能を使用しています。</p>



<h2 class="wp-block-heading jinr-heading d--bold">まとめ</h2>



<p class="wp-block-paragraph">VSCodeでGitのrebaseを実施する方法について解説しました。<span class="marker"><strong>rebase</strong></span>とは、Gitで提供されるコマンドの一種です。</p>



<p class="wp-block-paragraph">rebaseはいくつかの使用ケースが考えられるかと思いますが、よくある主要な使い方だと思われる以下の３種類の方法について、概要図なども交えて紹介しています。</p>



<ol class="wp-block-list jinr-list">
<li>開発コミットをつなげなおす</li>



<li>複数コミットを一つにまとめる</li>



<li>コミットメッセージを修正する</li>
</ol>



<p class="wp-block-paragraph">rebaseは、gitコマンドの中でも扱いが少し難しいものであると感じますが、コミットログを綺麗にする際にとても便利ですので、参考にしていただければと思います。</p>


<section class="b--jinr-block b--jinr-blogcard d--blogcard-hover-up d--blogcard-style1 d--blogcard-mysite t--round "><div class="a--blogcard-label ef">あわせて読みたい</div><a class="o--blogcard-link t--round" href="https://tech.nkhn37.net/python-tech-summary-page/"><div class="c--blogcard-image"><img decoding="async" class="a--blogcard-img-src" width="128" height="72" src="https://tech.nkhn37.net/wp-content/uploads/2024/08/Python-Tech-Pythonプログラミングガイド_new1-640x360.jpg" alt="【Python Tech】プログラミングガイド" /></div><div class="a--blogcard-title d--bold">【Python Tech】プログラミングガイド</div></a></section>]]></content:encoded>
					
					<wfw:commentRss>https://tech.nkhn37.net/git-rebase-vscode-basic/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Disk: Enhanced  を使用したページ キャッシュ

Served from: tech.nkhn37.net @ 2026-06-07 03:31:31 by W3 Total Cache
-->