2
1

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コマンド

2
Last updated at Posted at 2019-11-17

サーバー上で、修正を反映する時に使うgitコマンドメモです。

###ブランチ確認

git branch

全部ブランチ一覧

git branch -a

###状況確認

git status

###スタッシュ

git stash save "your comment"

###プル

git pull origin master

###ブランチ切り替え

 git checkout [ブランチ名]

※単体ファイルのみ戻す

git checkout [ファイルパス]

###フェッチ
リモートにあるブランチを最新のものに更新します

git fetch

ログ確認

git履歴から対象の文字列(-S メッセージから)を探します

git log -S"hogehoge"

※対象ファイルを絞る場合

git log -S"hogehoge" ./test.java

クローン

対象のリポジトリを自分の環境(ローカル)にもってきます

git clone [クローンしたいリポジトリ] [クローン先のディレクトリ(省略可)]

削除

マージ済みのブランチのみ削除


どちらも同じ
$ git branch --delete [ブランチ名]
$ git branch -d [ブランチ名]

マージ済みのブランチのみ削除ができる
マージされていないブランチを削除しようとすると下記のようなエラーがでます
(error: Cannot delete the branch 'ブランチ名' which you are currently on)
マージされていないブランチを削除したいときは削除コマンド2を

強制削除

$ git branch -D [ブランチ名]

どんなローカルブランチも削除できる

エラー回避

remote: error: cannot lock ref

ローカルに到達不能な追跡ブランチがのこっていたことが原因

以下を実行し到達不能なコミットを掃除す

git remote prune origin

ファイル差分ないが、差分として誤認される場合

git config core.filemode false

その他

Git で現在のコミット分調べる

git rev-parse HEAD
Git 現地点まで差分とるコマンド
git archive --format=zip --prefix=archive/ HEAD `git diff --name-only [コミットナンバー] HEAD --diff-filter=ACMR` -o archive.zip

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?