Thursday, 29 August 2019

Renaming and Moving files in Git by Raj Gupta

Renaming file by using Git


Administrator@EC2AMAZ-H8K4U2K MINGW64 ~/projects/Amazon-Web-Services-AWS-Cloud-Engineer/level1 (master)
$ cd level2/

Administrator@EC2AMAZ-H8K4U2K MINGW64 ~/projects/Amazon-Web-Services-AWS-Cloud-Engineer/level1/level2 (master)
$ cd level3/

Administrator@EC2AMAZ-H8K4U2K MINGW64 ~/projects/Amazon-Web-Services-AWS-Cloud-Engineer/level1/level2/level3 (master)
$ ls
raj3.txt

Administrator@EC2AMAZ-H8K4U2K MINGW64 ~/projects/Amazon-Web-Services-AWS-Cloud-Engineer/level1/level2/level3 (master)
$ git mv raj3.txt raj10.txt

Administrator@EC2AMAZ-H8K4U2K MINGW64 ~/projects/Amazon-Web-Services-AWS-Cloud-Engineer/level1/level2/level3 (master)
$ ls
raj10.txt

Administrator@EC2AMAZ-H8K4U2K MINGW64 ~/projects/Amazon-Web-Services-AWS-Cloud-Engineer/level1/level2/level3 (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        renamed:    raj3.txt -> raj10.txt


Administrator@EC2AMAZ-H8K4U2K MINGW64 ~/projects/Amazon-Web-Services-AWS-Cloud-Engineer/level1/level2/level3 (master)
$ git commit -m "rename file"
[master 0b8224b] rename file
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename level1/level2/level3/{raj3.txt => raj10.txt} (100%)

Administrator@EC2AMAZ-H8K4U2K MINGW64 ~/projects/Amazon-Web-Services-AWS-Cloud-Engineer/level1/level2/level3 (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 4 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

Administrator@EC2AMAZ-H8K4U2K MINGW64 ~/projects/Amazon-Web-Services-AWS-Cloud-Engineer/level1/level2/level3 (master)
$ cd ..

Administrator@EC2AMAZ-H8K4U2K MINGW64 ~/projects/Amazon-Web-Services-AWS-Cloud-Engineer/level1/level2 (master)
$ ls
level3/  raj2.txt

Administrator@EC2AMAZ-H8K4U2K MINGW64 ~/projects/Amazon-Web-Services-AWS-Cloud-Engineer/level1/level2 (master)
$


-------------------------------------------------------------------------------------------------------------------------

Renaming files without using Git command


Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ ls
Dockerfile  pom.xml  README.md  server/  start.txt  webapp/

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ mv start.txt start2.txt

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    start.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        start2.txt

no changes added to commit (use "git add" and/or "git commit -a")

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git add -A

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        renamed:    start.txt -> start2.txt

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)
$ git commit -m "rename the file"
[master e144111] rename the file
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename start.txt => start2.txt (100%)

Administrator@EC2AMAZ-8EUJ4RB MINGW64 ~/projects/hello-world (master)




No comments:

Post a Comment