0
0

gitでブランチ分岐をグラフ表示の履歴に残す方法

Posted at

gitでブランチ分岐をグラフ表示の履歴に残す方法

やりたいこと

  • 以下のような感じで分岐してマージしたという履歴を残したい
$ git log --graph
*   commit 7ca02b4e006886117d6a509f371f670729bd2515
|\  Merge: 798df58 181e05e
| | Author: You <you@example.com>
| | Date:   Fri Jun 7 12:11:31 2024 +0900
| | 
| |     Merge branch 'example-branch'
| | 
| * commit 181e05e9a31667c0dcf0093b2aa10accc8fe1853
| | Author: You <you@example.com>
| | Date:   Fri Jun 7 12:06:18 2024 +0900
| | 
| |     commit message 2
| | 
| * commit e3a4d6eb74229b6ab06da4a3d083e173f4a1091c
| | Author: You <you@example.com>
| | Date:   Fri Jun 7 12:05:50 2024 +0900
| | 
| |     commit message 1
| | 

結論

  • git merge --no-ff [branch]
  • git branch -d [branch]
git switch -c [マージ元ブランチ]
echo "hello world" > hello.txt
git add hello.txt
git commit -m "add hello"
git switch [マージ先ブランチ]
git merge --no-ff --no-edit [マージ元ブランチ]
git branch -d [マージ元ブランチ]

補足

  • git config --global --add merge.ff false でデフォルト設定を --no-ff にしておくと便利
    • ただし --global は任意
  • git merge --no-ff を実行するとマージメッセージをeditorで設定することができる
    • --no-edit にすると、editorが開かずにデフォルトのマージメッセージが設定される
  • git branch -d [branch] はブランチを削除するコマンド
    • -D オプションだと、履歴ごと消える
      • reflogにも残らないから消えてしまう
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0