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.

GitHub再入門(基本操作)

Last updated at Posted at 2018-04-15

基本操作

1. ファイル登録
2. ファイル更新
3. コミット
4. ファイル解除

status_image.png

5. 差分確認

diff_image.png

1. ファイル登録

1-1. ファイル登録(untracked->staged)

cmd
echo "# create" > file_1.md
git add file_1.md

file_add.png

1-2. 論理キャンセル(staged->untracked)

cmd
git reset HEAD file_1.md

file_add_cancel.png

2. ファイル更新

2-1. ファイル更新(unmodified->modified->staged)

cmd
echo "# update" >> file_1.md
git add file_1.md

file_update.png

2-2. 論理キャンセル(staged->modified)

cmd
git reset HEAD file_1.md

file_update_cancel.png

2-3. stagedまでの物理キャンセル

cmd
git checkout file_1.md

checkout_staged.png

2-4. 最新コミットまでの物理キャンセル

cmd
git checkout HEAD file_1.md

checkout_head.png

3. コミット

3-1. 通常コミット

cmd
git commit -m "coment"

commit.png

3-2. ステージング省略コミット(add + commit)

cmd
git commit -a -m "coment"

commit-a.png

(*)untrackedなファイルに対する省略コミットは不可

3-3. このコミットを最新コミットに統合してコミット

cmd
git commit --amend -m "coment"

commit--amend.png

3-4. 論理キャンセル(最新コミット直前の復元)

cmd
git reset --soft HEAD^

reset--soft.png

3-5. 物理キャンセル(前回コミット直後の復元)

cmd
git reset --hard HEAD^

reset--hard.png

4. ファイル解除

4-1. 論理解除(ファイルは削除されない)

cmd
git rm --cached file_*

rm-cached.png

4-2. 物理解除(ファイルは削除される)

cmd
git rm -f file_3.md
git rm file_*

rm.png

4-3. 物理移動

cmd
git mv file_1.md file_4.md

mv.png

5. 差分確認

diff_image.png

5-1. modifiedとstagedの比較

cmd
git diff file_1.md

5-2. stagedと最新コミットの比較

cmd
git diff --staged file_1.md

5-3. modified+stagedと最新コミットの比較

cmd
git diff HEAD file_1.md

diff.png

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?