ablog

不器用で落着きのない技術者のメモ

日常的な git

変更されたファイルを commit する

  • 変更されたファイルを調べる。
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 8 commits.
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   scripts/stat_solaris.sh
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	oracle/tools/session_wait/
#	oracle/tools/sysstat/
no changes added to commit (use "git add" and/or "git commit -a")
  • 変更箇所を確認する。
$ git diff scripts/stat_solaris.sh 
diff --git a/scripts/stat_solaris.sh b/scripts/stat_solaris.sh
index 5fffb80..fe2205d 100755
--- a/scripts/stat_solaris.sh
+++ b/scripts/stat_solaris.sh
@@ -73,3 +73,5 @@ PID=${SH_PID}
 
  
 done
+
+
  • 変更されたファイルを commit する。
$ git commit -m'deleted a line' scripts/stat_solaris.sh 
[master]: created 9b19e9a: "deleted a line"
 1 files changed, 2 insertions(+), 0 deletions(-)
$ git add oracle/tools/session_wait/*
$ git add oracle/tools/sysstat/*
$ git commit -m'shell scripts for oracle'
[master]: created dc920aa: "shell scripts for oracle"
 6 files changed, 99 insertions(+), 0 deletions(-)
 create mode 100755 oracle/tools/session_wait/exec_session_wait9.sh
 create mode 100755 oracle/tools/session_wait/session_wait9.sh
 create mode 100755 oracle/tools/session_wait/seswait9.sql
 create mode 100755 oracle/tools/sysstat/exec_sysstat9.sh
 create mode 100755 oracle/tools/sysstat/sysstat9.sh
 create mode 100755 oracle/tools/sysstat/sysstat9.sql
$ git push git@github.com:yoheia/yoheia.git master
Counting objects: 21, done.
Compressing objects: 100% (16/16), done.
Writing objects: 100% (16/16), 2.01 KiB, done.
Total 16 (delta 5), reused 0 (delta 0)
To git@github.com:yoheia/yoheia.git
   db7b758..dc920aa  master -> master

古いバージョンを取り出す

  • コミットログを確認する。
$ git log
commit dc920aaf41c67269a8cb81bf5d91b6270c470ea3
Author: yoheia <...>
Date:   Thu Aug 6 13:35:38 2009 +0900

    shell scripts for oracle

commit 9b19e9a69a1e0ac86f0793da0df4858ace3de8ff
Author: yoheia <...>
Date:   Thu Aug 6 13:30:51 2009 +0900

    deleted a line

...
  • 古いバージョンに戻す。
$ git revert 9b19e9a69a1e0ac86f0793da0df4858ace3de8ff
Finished one revert.
[master]: created a967177: "Revert "deleted a line""
 1 files changed, 0 insertions(+), 2 deletions(-)
  • 戻ったか確認する。
$ tail stat_solaris.sh 
... 
PID=${SH_PID}
...
  • コミットログを確認する。
$ git log
commit a9671770815fd6ebc750f26f7c6a75610f053a5e
Author: yoheia <...>
Date:   Thu Aug 6 13:49:30 2009 +0900

    Revert "deleted a line"
    
    This reverts commit 9b19e9a69a1e0ac86f0793da0df4858ace3de8ff.

commit dc920aaf41c67269a8cb81bf5d91b6270c470ea3
Author: yoheia <...>
Date:   Thu Aug 6 13:35:38 2009 +0900

    shell scripts for oracle

commit 9b19e9a69a1e0ac86f0793da0df4858ace3de8ff
Author: yoheia <...>
Date:   Thu Aug 6 13:30:51 2009 +0900

    deleted a line
...
  • 最新の状態にもどす。
$ git revert dc920aaf41c67269a8cb81bf5d91b6270c470ea3
Finished one revert.
[master]: created 94ce362: "Revert "shell scripts for oracle""
 6 files changed, 0 insertions(+), 99 deletions(-)
 delete mode 100755 oracle/tools/session_wait/exec_session_wait9.sh
 delete mode 100755 oracle/tools/session_wait/session_wait9.sh
 delete mode 100755 oracle/tools/session_wait/seswait9.sql
 delete mode 100755 oracle/tools/sysstat/exec_sysstat9.sh
 delete mode 100755 oracle/tools/sysstat/sysstat9.sh
 delete mode 100755 oracle/tools/sysstat/sysstat9.sql
  • コミットログを確認する。
$ git log
commit 94ce3623233c34df7330a88c2817c935cec87d6a
Author: yoheia <...>
Date:   Thu Aug 6 13:54:10 2009 +0900

    Revert "shell scripts for oracle"
    
    This reverts commit dc920aaf41c67269a8cb81bf5d91b6270c470ea3.

commit a9671770815fd6ebc750f26f7c6a75610f053a5e
Author: yoheia <...>
Date:   Thu Aug 6 13:49:30 2009 +0900

    Revert "deleted a line"
    
    This reverts commit 9b19e9a69a1e0ac86f0793da0df4858ace3de8ff.

commit dc920aaf41c67269a8cb81bf5d91b6270c470ea3
Author: yoheia <...>
Date:   Thu Aug 6 13:35:38 2009 +0900

    shell scripts for oracle

...


[参考]
Gitを使いこなすための20のコマンド | OSDN Magazine


[関連]
github を使ってみた - ablog
Windows でも github を使ってみた - ablog
github のリポジトリにディレクトリを作成して commit する - ablog
github にリポジトリを作成したのと別のマシンからファイルを作成したり削除したりする - ablog
ローカルに git のリポジトリを作ってみた - ablog