Closed fr-sato closed 10 years ago
本課題は17:45開始、工数見積もり合計4時間で行います。
内訳
実施日 | 作業時間 | 内容 |
---|---|---|
4/16 | 45分 | 課題4まで |
4/17 | 2時間30分 | 課題5-13 |
4/17 | 30分 | Markdown記入・確認 |
以上、よろしくお願いいたします。
4/17の作業時間は、15:15~17:50でした。
4/18 本日の作業開始は14:10といたします。
番号付きリストの番号を途中から始められなかったため、前日分と併せて再提出させていただきます。 ご確認宜しくお願い致します。
リポジトリを作成
$ git init
$ git init
Initialized empty Git repository in /home/ *** /.git/
$ ll
total 124
-rw-rw-r-- 1 *** *** 952 Apr 7 06:18 dl.tar.gz
drwxrwxr-x 2 *** *** 4096 Apr 7 06:17 doc
-rw-rw-r-- 1 *** *** 44645 Apr 7 06:16 ds.zip
drwxrwxr-x 2 *** *** 4096 May 26 2010 gist414375-24c6049f621f07db839e8cdd133e396756d642db
drwxrwxr-x 2 *** *** 4096 Apr 7 06:17 nerdtree_plugin
drwxrwxr-x 2 *** *** 4096 Apr 7 06:17 plugin
drwxrwxr-x 3 *** *** 4096 Mar 20 02:49 public_html
-rw-rw-r-- 1 *** *** 153 Apr 14 07:08 regexp.txt
-rw-rw-r-- 1 *** *** 43528 Apr 4 07:38 TEST
drwxrwxr-x 8 *** *** 4096 Apr 11 08:58 tmux-powerline
drwxrwxr-x 2 *** *** 4096 Apr 8 06:08 work
作成したリポジトリに新規ファイルを追加
$ git add [file_name]
$ git add gittest.txt
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: gittest.txt
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .vimrc
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .bash_history
# .bash_logout
# .bash_profile
# .bashrc
# .composer/
# .lesshst
# .mysql_history
# .ssh/
# .swp
# .tmux-powerlinerc
# .tmux/
# .vim/
# .viminfo
# TEST
# dl.tar.gz
# doc/
# ds.zip
# gist414375-24c6049f621f07db839e8cdd133e396756d642db/
# gittest2.txt
# nerdtree_plugin/
# plugin/
# public_html/
# regexp.txt
# test3.txt
# tmux-powerline/
# work/
現在のリポジトリの状態を確認(新規ファイル、追加ファイルなど)
$ git status
$ git add gittest2.txt
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: gittest.txt
# new file: gittest2.txt
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .vimrc
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .bash_history
# .bash_logout
# .bash_profile
# .bashrc
# .composer/
# .lesshst
# .mysql_history
# .ssh/
# .swp
# .tmux-powerlinerc
# .tmux/
# .vim/
# .viminfo
# TEST
# dl.tar.gz
# doc/
# ds.zip
# gist414375-24c6049f621f07db839e8cdd133e396756d642db/
# nerdtree_plugin/
# plugin/
# public_html/
# regexp.txt
# test3.txt
# tmux-powerline/
# work/
追加したファイルを追加対象から外す
$ git rm --cached [file_name]
--cached
:indexから外すが、ファイルは残す。$ git rm --cached gittest2.txt
rm 'gittest2.txt'
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: gittest.txt
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .vimrc
再度ファイルを追加後、コミット
$ git commit -m "comment"
$ git add gittest2.txt
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: gittest.txt
# new file: gittest2.txt
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .vimrc
(中略)
$ git commit -m "first commit"
[master 2d5193d] first commit
Committer: EC2 Default User < *** *** .ap-northeast-1.compute.internal>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
2
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
2 files changed, 2 insertions(+)
create mode 100644 gittest.txt
create mode 100644 gittest2.txt
追加したファイルを編集、保存し、差分を表示
$ git diff
$ vim gittest2.txt
$ git diff
diff --git a/.vimrc b/.vimrc
index eb43e2b..f0f63ad 100755
--- a/.vimrc
+++ b/.vimrc
@@ -31,8 +31,3 @@
inoremap <Up> <Nop>
inoremap <Down> <Nop>
inoremap <Left> <Nop>
inoremap <Right> <Nop>
-
-"powerlineインストール
-NeoBundle 'alpaca-tc/alpaca_powertabline'
-NeoBundle 'https://github.com/Lokaltog/powerline.git'
-
diff --git a/gittest2.txt b/gittest2.txt
index c754988..5bdb67b 100644
--- a/gittest2.txt
+++ b/gittest2.txt
@@ -1 +1 @@
-tetetest
+testtesttest
編集した内容をGitコマンドを用いて編集前に戻す
$ git checkout -- [file_name]
$ cat gittest2.txt
testtesttest
$ git checkout -- gittest2.txt
$ cat gittest2.txt
tetetest
ファイルをGit管理から削除してコミット
$ git rm [file_name]
$ ls -l
total 136
-rw-rw-r-- 1 *** *** 952 Apr 7 06:18 dl.tar.gz
drwxrwxr-x 2 *** *** 4096 Apr 7 06:17 doc
-rw-rw-r-- 1 *** *** 44645 Apr 7 06:16 ds.zip
drwxrwxr-x 2 *** *** 4096 May 26 2010 gist414375-24c6049f621f07db839e8cdd133e396756d642db
-rw-rw-r-- 1 *** *** 9 Apr 17 07:51 gittest2.txt
-rw-rw-r-- 1 *** *** 5 Apr 17 08:00 gittest.txt
drwxrwxr-x 2 *** *** 4096 Apr 7 06:17 nerdtree_plugin
drwxrwxr-x 2 *** *** 4096 Apr 7 06:17 plugin
drwxrwxr-x 3 *** *** 4096 Mar 20 02:49 public_html
-rw-rw-r-- 1 *** *** 153 Apr 14 07:08 regexp.txt
-rw-rw-r-- 1 *** *** 43528 Apr 4 07:38 TEST
-rw-rw-r-- 1 *** *** 9 Apr 17 05:18 test3.txt
drwxrwxr-x 8 *** *** 4096 Apr 11 08:58 tmux-powerline
drwxrwxr-x 2 *** *** 4096 Apr 8 06:08 work
$ git rm gittest.txt
rm 'gittest.txt'
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: gittest.txt
$ git commit -m "deleted gittest.txt"
[master 687a9f3] deleted gittest.txt
Committer: EC2 Default User < *** .ap-northeast-1.compute.internal>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
fter doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 deletion(-)
delete mode 100644 gittest.txt
$ git log
commit 687a9f32b4ae5c1efb13ec588d8a3ce51ee6e2c3
Author: EC2 Default User < *** .ap-north
Date: Thu Apr 17 08:06:25 2014 +0000
deleted gittest.txt
commit 2d5193d0e67578f850999c615dc74dd288626ba0
Author: EC2 Default User < *** .ap-north
Date: Thu Apr 17 06:51:58 2014 +0000
first commit
commit 67cc9cae1a4276bc07afcff4ce37091d18039158
Author: EC2 Default User < *** .ap-north
Date: Wed Apr 16 09:18:29 2014 +0000
first commit
$ ls -l
total 132
-rw-rw-r-- 1 *** *** 952 Apr 7 06:18 dl.tar.gz
drwxrwxr-x 2 *** *** 4096 Apr 7 06:17 doc
-rw-rw-r-- 1 *** *** 44645 Apr 7 06:16 ds.zip
drwxrwxr-x 2 *** *** 4096 May 26 2010 gist414375-24c6049f621f07db839e8cdd133e396756d642db
-rw-rw-r-- 1 *** *** 9 Apr 17 07:51 gittest2.txt
drwxrwxr-x 2 *** *** 4096 Apr 7 06:17 nerdtree_plugin
drwxrwxr-x 2 *** *** 4096 Apr 7 06:17 plugin
drwxrwxr-x 3 *** *** 4096 Mar 20 02:49 public_html
-rw-rw-r-- 1 *** *** 153 Apr 14 07:08 regexp.txt
-rw-rw-r-- 1 *** *** 43528 Apr 4 07:38 TEST
-rw-rw-r-- 1 *** *** 9 Apr 17 05:18 test3.txt
drwxrwxr-x 8 *** *** 4096 Apr 11 08:58 tmux-powerline
drwxrwxr-x 2 *** *** 4096 Apr 8 06:08 work
直前のコミットを取り消し(ファイルを削除する前の状態に戻す)
$ git reset --hard HEAD^
$ git log
commit 687a9f32b4ae5c1efb13ec588d8a3ce51ee6e2c3
Author: EC2 Default User < *** *** .ap-north
Date: Thu Apr 17 08:06:25 2014 +0000
deleted gittest.txt
commit 2d5193d0e67578f850999c615dc74dd288626ba0
Author: EC2 Default User < *** *** .ap-north
Date: Thu Apr 17 06:51:58 2014 +0000
first commit
commit 67cc9cae1a4276bc07afcff4ce37091d18039158
Author: EC2 Default User < *** *** .ap-north
Date: Wed Apr 16 09:18:29 2014 +0000
first commit
$ git reset --hard HEAD^
HEAD is now at 2d5193d first commit
$ git log
commit 2d5193d0e67578f850999c615dc74dd288626ba0
Author: EC2 Default User < *** *** .ap-north
Date: Thu Apr 17 06:51:58 2014 +0000
first commit
commit 67cc9cae1a4276bc07afcff4ce37091d18039158
Author: EC2 Default User < *** *** .ap-north
Date: Wed Apr 16 09:18:29 2014 +0000
first commit
$ ls -l
total 136
-rw-rw-r-- 1 *** *** 952 Apr 7 06:18 dl.tar.gz
drwxrwxr-x 2 *** *** 4096 Apr 7 06:17 doc
-rw-rw-r-- 1 *** *** 44645 Apr 7 06:16 ds.zip
drwxrwxr-x 2 *** *** 4096 May 26 2010 gist414375-24c6049f621f07db839e8cdd133e396756d642db
-rw-rw-r-- 1 *** *** 9 Apr 17 07:51 gittest2.txt
-rw-rw-r-- 1 *** *** 5 Apr 17 08:22 gittest.txt
drwxrwxr-x 2 *** *** 4096 Apr 7 06:17 nerdtree_plugin
drwxrwxr-x 2 *** *** 4096 Apr 7 06:17 plugin
drwxrwxr-x 3 *** *** 4096 Mar 20 02:49 public_html
-rw-rw-r-- 1 *** *** 153 Apr 14 07:08 regexp.txt
-rw-rw-r-- 1 *** *** 43528 Apr 4 07:38 TEST
-rw-rw-r-- 1 *** *** 9 Apr 17 05:18 test3.txt
drwxrwxr-x 8 *** *** 4096 Apr 11 08:58 tmux-powerline
drwxrwxr-x 2 *** *** 4096 Apr 8 06:08 work
今までのGitのログを表示
$ git log
$ git log
commit 2d5193d0e67578f850999c615dc74dd288626ba0
Author: EC2 Default User < *** *** .ap-north
Date: Thu Apr 17 06:51:58 2014 +0000
first commit
commit 67cc9cae1a4276bc07afcff4ce37091d18039158
Author: EC2 Default User < *** *** .ap-north
Date: Wed Apr 16 09:18:29 2014 +0000
first commit
いづれか1つのファイルをGit管理に含めないように設定
.gitignore
(無視ファイルリスト)を作成$ vim .gitignore
$ cat .gitignore
gittest2.txt
$ vim gittest2.txt
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: gittest2.txt
#
$ git rm --cached gittest2.txt
rm 'gittest2.txt'
[ec2-user@ip-10-134-139-29 ~]$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: gittest2.txt
#
$ vim gittest2.txt
$ git add gittest2.txt
The following paths are ignored by one of your .gitignore files:
gittest2.txt
Use -f if you really want to add them.
fatal: no files added
ブランチを作って移動
$ git branch
:(引数なし)ブランチの表示(引数あり)ブランチを作成$ git checkout [branch_name]
:指定したブランチへ移動$ git branch
* master
$ git branch bugfix
$ git branch
bugfix
* master
$ git checkout bugfix
D gittest2.txt
Switched to branch 'bugfix'
作ったブランチで新たな新規ファイルを追加、コミットした後、前のブランチにマージ
$ git merge [branch_name]
$ git commit -m "added test3.txt to bugfix"
[bugfix 3d23b6b] added test3.txt to bugfix
Committer: EC2 Default User < *** *** .ap-northeast-1.compute.internal>
2 files changed, 1 insertion(+), 1 deletion(-)
delete mode 100644 gittest2.txt
create mode 100644 test3.txt
$ git branch
* bugfix
master
$ git checkout master
Switched to branch 'master'
$ git branch
bugfix
* master
$ git merge bugfix
Updating 04c7047..3d23b6b
Fast-forward
gittest2.txt | 1 -
test3.txt | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
delete mode 100644 gittest2.txt
create mode 100644 test3.txt
確認しました! 気になった点があるので下記をもう一度トライしてみてください。
.git
は削除しておきましょう。git status
でmodified: gittest2.txt
が表示されているのが気になりました。
新たに作ったリポジトリの中で実行してみましょう。これ以外は大丈夫でした!
ご指摘を基に再チャレンジしました。如何でしょうか。
課題1
$ mkdir testGit
$ ls -al
total 104
drwx------ 8 *** *** r 4096 Apr 18 08:24 .
drwxr-xr-x 3 root root 4096 Dec 10 23:47 ..
-rw------- 1 *** *** 22614 Apr 18 07:25 .bash_history
-rw-r--r-- 1 *** *** 18 Sep 4 2013 .bash_logout
-rw-r--r-- 1 *** *** 176 Sep 4 2013 .bash_profile
-rw-r--r-- 1 *** *** 124 Sep 4 2013 .bashrc
drwxrwxr-x 3 *** *** 4096 Mar 19 09:49 .composer
-rw-rw-r-- 1 *** *** 21 Apr 18 05:48 gittest.txt
-rw------- 1 *** *** 32 Mar 25 07:21 .mysql_history
drwxrw---- 3 *** *** 4096 Apr 7 07:05 .pki
drwxrwxr-x 3 *** *** 4096 Mar 20 02:49 public_html
-rw-rw-r-- 1 *** *** 153 Apr 14 07:08 regexp.txt
drwx------ 2 *** *** 4096 Apr 15 03:53 .ssh
-rw-rw-r-- 1 *** *** 9 Apr 18 06:53 test3.txt
drwxrwxr-x 2 *** *** 4096 Apr 18 08:24 testGit
-rwxr-xr-x 1 *** *** 1486 Apr 14 06:28 .tmux.conf
drwxrwxr-x 5 *** *** 4096 Apr 15 06:09 .vim
-rw------- 1 *** *** 10666 Apr 18 08:10 .viminfo
-rwxrwxr-x 1 *** *** 986 Apr 17 07:51 .vimrc
$ cd testGit/
$ git init
Initialized empty Git repository in /home/ ***/testGit/.git/
$ ls -al
total 12
drwxrwxr-x 3 *** *** 4096 Apr 18 08:26 .
drwx------ 8 *** *** 4096 Apr 18 08:24 ..
drwxrwxr-x 7 *** *** 4096 Apr 18 08:26 .git
課題11(コミットしていないファイルを無視する)
$ touch .gitignore
$ ls -al
total 12
drwxrwxr-x 3 *** *** 4096 Apr 18 08:31 .
drwx------ 8 *** *** 4096 Apr 18 08:24 ..
drwxrwxr-x 7 *** *** 4096 Apr 18 08:26 .git
-rw-rw-r-- 1 *** *** 0 Apr 18 08:31 .gitignore
$ vim .gitignore
$ cat .gitignore
gittest.txt
$ touch gittest.txt
$ ls -al
total 16
drwxrwxr-x 3 *** *** 4096 Apr 18 08:33 .
drwx------ 8 *** *** 4096 Apr 18 08:32 ..
drwxrwxr-x 7 *** *** 4096 Apr 18 08:33 .git
-rw-rw-r-- 1 *** *** 12 Apr 18 08:32 .gitignore
-rw-rw-r-- 1 *** *** 0 Apr 18 08:33 gittest.txt
$ git add gittest.txt
The following paths are ignored by one of your .gitignore files:
gittest.txt
Use -f if you really want to add them.
fatal: no files added
確認しました。問題ないです!! :+1:
■目的
Gitの基本的なコマンドを使い一連のバージョン管理の流れを学びます。
■課題
調べた結果はこのIssueのコメントにまとめて下さい。