Operating Rename in Git

So far, both Tom and Jerry are using manual commands to compile their projects. Now, Jerry decided to create a Makefile for the project and also put a name for the "string.c" file.

 [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 is pointing R before the file name to indicate that the file has been renamed.

For commit operations, Jerry uses the -a extension, which makes git commit automatically find modified files.

 [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%)

After committing, he pushes his changes to the repository.

 [jerry @ CentOS src] $ git push origin master 

The above command will produce the following result:

 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 gituser@git.server.com: project.git
7d9ea97.94f7b26 master -> master

Now, other programmers can observe changes by updating their local repository.

According to Tutorialspoint

Previous article: Online Repository in Git

Next post: Delete activity in Git

5 ★ | 1 Vote

May be interested

  • Delete operation in GitPhoto of Delete operation in Git
    tom updates the local repository and finds the compiled binary in the src directory. after observing the commit message, he realizes that this code is added by jerry.
  • Fixed a bug in GitPhoto of Fixed a bug in Git
    being human, everyone makes mistakes. so each vcs provides a feature to fix errors at some point. git provides a feature that we can use to undo the modifications made on the local repository.
  • Tag operation in GitPhoto of Tag operation in Git
    tag operation allows to provide meaning names for specific versions in the repository. suppose tom and jerry decide to tag them into their project code so that they can then access it easily.
  • Patch operation in GitPhoto of Patch operation in Git
    the patch is a text file, its content is similar to git diff, but in parallel with the code, it also has metadata about commits such as commit ids, dates, commit messages ... we can create a patch from commits and others can apply them to their repository.
  • Managing branches in GitPhoto of Managing branches in Git
    branch operations allow creating different routes of development. we can use this activity to branch the development process into two different directions. for example, we published a version 6 product and we wanted to create a branch to develop 7.0 features that could be kept separate from bug fixes in version 6.0.
  • Conflict handling in GitPhoto of Conflict handling in Git
    jerry is working on the wchar_support branch. he changes the name of the feature and after checking, he repository his changes.