Git移動操作


顧名思義,移動操作將目錄或檔案從一個位置移動到另一個位置。例如,我們想要將原始碼移動到src目錄中。修改後的目錄結構將顯示如下:

Administrator@MY-PC /D/worksp/sample (master)
$ pwd
/D/worksp/sample

Administrator@MY-PC /D/worksp/sample (master)
$ ls
README.md  main.py

Administrator@MY-PC /D/worksp/sample (master)
$ mkdir src

Administrator@MY-PC /D/worksp/sample (master)
$ git mv main.py src/

Administrator@MY-PC /D/worksp/sample (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        renamed:    main.py -> src/main.py

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:   src/main.py

為了使這些更改永久性,必須將修改的目錄結構推播到遠端儲存庫,以便其他開發人員可以看到這些更改。

$ git add .

Administrator@MY-PC /D/worksp/sample (master)
$ git commit -m "Modified directory structure"
[master 186df84] Modified directory structure
 1 file changed, 3 insertions(+)
 rename main.py => src/main.py (78%)

Administrator@MY-PC /D/worksp/sample (master)
$ git push origin master
Username for 'http://git.oschina.net': [email protected]
Password for 'http://[email protected]@git.oschina.net':
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 491 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To http://git.oschina.net/yiibai/sample.git
   ef07ab5..186df84  master -> master

在其它開發人員的本地儲存庫中,在執行git pull操作之前,它將顯示舊的目錄結構。在另外一台開發者機器上,執行以下命令 -

yiibai@ubuntu:~/git/sample$ pwd
/home/yiibai/git/sample
yiibai@ubuntu:~/git/sample$ ls
main.py  master  README.md
yiibai@ubuntu:~/git/sample$

但是在執行git pull操作之後,目錄結構將被更新。 現在,假設在另外一個開發人員(minsu)執行git pull操作之後,就可以看到目錄中的src目錄和檔案了。

yiibai@ubuntu:~/git/sample$ git pull
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 10 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (10/10), done.
From http://git.oschina.net/yiibai/sample
   01c5462..186df84  master     -> origin/master
Updating 01c5462..186df84
Fast-forward
 main.py => src/main.py | 11 +++++++++++
 1 file changed, 11 insertions(+)
 rename main.py => src/main.py (58%)
yiibai@ubuntu:~/git/sample$ ls
master  README.md  src
yiibai@ubuntu:~/git/sample$ ls src/
main.py
yiibai@ubuntu:~/git/sample$