0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Git 新規追加ファイルがある状態の差分でもstashしたい

0
Last updated at Posted at 2025-12-01

概要

Gitを使ってチームで開発をしていると、作業中ブランチの作成元ブランチが更新されたのでrebaseしたい時がある。この時に$ git stashを使って差分を一時退避させる事がある。ただ、差分にUntracked files(新規追加ファイル)がある場合単純にstashしてもUntrackedなファイルは退避されない。新規追加ファイルも含めてstashで退避させる方法を簡単にまとめる。

方法

  1. 下記を実行してステージ上のUntrackedファイルも含めてスタッシュ(-m "わかりやすいスタッシュコメントを記載"は必須ではない。)

    git stash push -m "わかりやすいスタッシュコメントを記載" --include-untracked
    
  2. rebaseなどの作業を実施

  3. 作業中ブランチに戻り、下記を実行して復元

    git stash pop
    

参考文献

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?