GIT – diff, remove and rename

Before this if you want to see Git workflow/ three tree architecture

To check the difference between Repository and working directory using following command-

git diff

To get the difference in words instead  of whole statement highlighted with diff, use following command-

git diff --color-words

To check  staged changes difference, use following command-

git diff --staged

To delete file from working directory and from repo, use following command-

git rm file-to-delete.txt

The file will be staged with this command so you dont need to explicitly stage the deleted file.

Commit this file-

git commit -m "file deleted."

Please note while doing so the files will be permanently deleted and not found in thrash to recover. So use this command wisely if the file is not in the repo for you to pull back.

Rename file in repository and working folder, use following command-

 git mv filebeforerenaming.txt fileafterrenaming.txt

This shall rename file and stage the changes. So this is not required to manually staged.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s