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?

More than 5 years have passed since last update.

Gitについて勉強する。第三弾 (gitの変更を取り消そう 編)

Last updated at Posted at 2019-10-03

gitの変更を取り消してみる

git checkout -- "ファイル名"

ワーキングディレクトリ内にある変更を取り消します。

  • git checkout -- "ファイル名"
  • git checkout -- "ディレクトリ名"

すべての変更を取り消す

  • git checkout -- .

git restore "ファイル名"

Gitバージョン2.23.0 から「git restore」コマンドが追加されたようです。
これは、「git checkout」にできることが多すぎるから、分割されたということらしいです。

下記コマンドで、先程のチェックアウトコマンドと同じことができます。

  • git restore "ファイル名"
  • git restore"ディレクトリ名"

すべての変更を取り消す

  • git restore .

git reset HEAD "ファイル名"

ステージングエリア内にある変更を取り消します。
ステージから消すだけなので、作業中のフォルダには反映されません。

  • git reset HEAD "ファイル名"
  • git reset HEAD "ディレクトリ名"

すべての変更を取り消す

  • git reset HEAD .

直前のコミットを取り消したいとき

git commit --amend

コミット内容を取り消すことができます。
あくまでローカルリポジトリを取り消すためpushしたものには実行しないようにしましょう。
gitの動作としては、ステージの内容で直前のコミットを上書きするイメージのほうが正しいです。

バージョン管理する必要のないファイルを設定する

.gitignoreファイルでバージョン管理しないファイルを指定できます。
.gitignoreファイルを作成し、対象のファイル名を書き込めばOKです。

次・第四弾

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?