顾名思义,移动操作将目录或文件从一个位置移动到另一个位置。例如,我们想要将源代码移动到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 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': 769728683@qq.com Password for 'http://769728683@qq.com@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/zyiz/sample.git ef07ab5..186df84 master -> master
在其它开发人员的本地存储库中,在执行git pull
操作之前,它将显示旧的目录结构。在另外一台开发者机器上,执行以下命令 -
zyiz@ubuntu:~/git/sample$ pwd /home/zyiz/git/sample zyiz@ubuntu:~/git/sample$ ls main.py master README.md zyiz@ubuntu:~/git/sample$
但是在执行git pull
操作之后,目录结构将被更新。 现在,假设在另外一个开发人员(minsu
)执行git pull
操作之后,就可以看到目录中的src
目录和文件了。
zyiz@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/zyiz/sample 01c5462..186df84 master -> origin/master Updating 01c5462..186df84 Fast-forward main.py => src/main.py | 11 +++++++++++ file changed, 11 insertions(+) rename main.py => src/main.py (58%) zyiz@ubuntu:~/git/sample$ ls master README.md src zyiz@ubuntu:~/git/sample$ ls src/ main.py zyiz@ubuntu:~/git/sample$