0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

現場で個人的によく使うGitコマンドまとめ

Last updated at Posted at 2017-08-15

概要

現場でGitコマンドごりごり触れていた時に、よく使っていたコマンドをまとめておきます。
備忘録用。

リモートブランチにPUSHする前(コミット後)の最終確認

リモートブランチ含めて、自分が現在いるブランチを確認

git branch -a

コミット履歴を出力し、コミットメッセージを確認

git log --d

コミット内容の確認

git show

修正内容のバックアップ(stashで残す方法)

stashで残す

git stash

stashした内容を戻す

git stash pop

修正内容のバックアップ(パッチファイルで残す方法)

パッチファイルを作って残す

git diff > diff.patch

パッチファイルを適用する

git apply diff.patch

適用したパッチファイルを外す

git apply -R diff.patch

mergeやrebaseを使わずにコンフリクト解消

これにより、マージコミットも作られず、コミット履歴がバラバラになるのを避けることができる。
ただし、コミットが1つの場合にのみ限る。

コミット履歴を出力し、該当のコミットIDを確認

git log --d

リモートの全ブランチを更新

git fetch --all

対象のリモートブランチを確認

git branch -r

リモートブランチをチェックアウト

git checkout [リモートリポジトリ名]

ローカルブランチとして一時的なブランチを作成

git checkout -b tmp

該当のコミットをIDを指定し、チェリーピック

git cherry-pick [コミットID]

元いたローカルブランチを作り直す

git branch -D [元いたローカルブランチ名]
git branch -m [元いたローカルブランチ名]
0
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?