Hoạt động Rename trong Git



Tới giờ, cả Tom và Jerry đều đang sử dụng các lệnh bằng tay để biên dịch dự án của họ. Bây giờ, Jerry quyết định tạo Makefile cho dự án và cũng đặt một tên cho file " string.c".

[jerry@CentOS project]$ pwd
/home/jerry/jerry_repo/project[jerry@CentOS project]$ ls
README src[jerry@CentOS project]$ cd src/[jerry@CentOS src]$ git add Makefile[jerry@CentOS src]$ git mv string.c string_operations.c[jerry@CentOS src]$ git status -s
A Makefile
R string.c −> string_operations.c

Git đang chỉ R trước tên file để chỉ rằng file đã được đặt lại tên.

Đối với hoạt động commit, Jerry sử dụng đuôi -a, mà làm cho git commit tự động tìm các file đã được chỉnh sửa.

[jerry@CentOS src]$ git commit -a -m 'Added Makefile and renamed strings.c to
string_operations.c '[master 94f7b26] Added Makefile and renamed strings.c to string_operations.c
1 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 src/Makefile
rename src/{string.c => string_operations.c} (100%)

Sau khi commit, anh ta push những thay đổi của anh ta tới repository.

[jerry@CentOS src]$ git push origin master

Lệnh trên sẽ tạo ra kết quả sau:

Counting objects: 6, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 396 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
To [email protected]:project.git
7d9ea97..94f7b26 master −> master

Bây giờ, các nhà lập trình khác có thể quan sát những thay đổi bằng cách cập nhật repository nội bộ của họ.