Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Git | ファイルの移動

概要

ファイルの移動

詳細

git では以下の2種類の方法でファイルを移動します。

$ git mv from_file to_file

これは、以下と同じです。

mv from_file to_file
git add to_file

サンプル(git mv)

$ git init
$ echo hoge > from_file
$ git add -A
$ git commit -m "add from_file"
[master (root-commit) f71aebd] add from_file
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 from_file
$ git mv from_file to_file
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       renamed:    from_file -> to_file
#
$ git commit -m "rename from_file to to_file"
[master 913b018] rename from_file to to_file
 1 files changed, 0 insertions(+), 0 deletions(-)
 rename from_file => to_file (100%)

サンプル(mv)

$ git init
$ echo hoge > from_file
$ git add -A
$ git commit -m "add from_file"
[master (root-commit) b4e9068] add from_file
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 from_file
$ mv from_file to_file
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    from_file
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       to_file
no changes added to commit (use "git add" and/or "git commit -a")
$ git add -A
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       renamed:    from_file -> to_file
#
$ git commit -m "rename from_file to to_file"
[master 73517dd] rename from_file to to_file
 1 files changed, 0 insertions(+), 0 deletions(-)
 rename from_file => to_file (100%)
$ git status
# On branch master
nothing to commit (working directory clean)