Welcome to the next phase of your Git journey! In Phase 5, we're diving deeper into essential Git commands that will make you a Git pro.
Log Commands
Command 1: git status
Before making any moves, it's always a good idea to check the lay of the land. git status
is your friend. It tells you what's happening in your Git world.
Example:
theshubhamgour@ubuntuM1:~/Desktop/git-hash$ git status
Command 2: git diff
Need to see the differences in your files? git diff
is the tool. Whether you want to compare your working directory with the last commit or check the changes in a specific file, this command has you covered.
Example:
git diff <filename>
Command 3: git diff --staged
So, you've staged some changes, but you're not quite ready to commit them. Use git diff --staged
to review what's about to be committed. It's like a final check before sealing the deal.
Example:
theshubhamgour@ubuntuM1:~/Desktop/git-hash$ git diff --staged
Command 4: git diff commitA..commitB
Ever wondered how two versions of a file differ? This command helps you compare them using their commit IDs. Understanding the changes between two specific points in time can be incredibly useful.
Example:
theshubhamgour@ubuntuM1:~/Desktop/git-hash$ git log file1.txt
theshubhamgour@ubuntuM1:~/Desktop/git-hash$ git diff d98f65..d0d054
Deleting a File
Deleting a file in Git is a two-step process. First, use git rm <filename>
to remove it. Then, commit your change with a descriptive comment, and finally, push the update to your repository.
Example:
theshubhamgour@ubuntuM1:~/Desktop/git-hash$ git rm file10.txt
theshubhamgour@ubuntuM1:~/Desktop/git-hash$ git commit -m "Deleted file10.txt - NA Cached"
theshubhamgour@ubuntuM1:~/Desktop/git-hash$ git push
Renaming a File/Folder
Change file or folder names seamlessly with git mv
. This command simplifies renaming while keeping the history intact. After renaming, commit the change and push it to your repository.
Example:
theshubhamgour@ubuntuM1:~/Desktop/git-hash$ git mv git-file file10.txt
theshubhamgour@ubuntuM1:~/Desktop/git-hash$ git commit -m "Renamed: git-file -> file10.txt"
theshubhamgour@ubuntuM1:~/Desktop/git-hash$ git push
Carry History for a New File
Sometimes, you'll want to carry over the history of an old file to a new one. Use git log --follow <new-name>
to do just that. This can be especially handy when you're restructuring your project.
Example:
theshubhamgour@ubuntuM1:~/Desktop/git-hash$ git log --follow file10.txt
With these commands and examples, you're well-equipped to navigate the Git universe with confidence. Git empowers you to track changes, collaborate effectively, and ensure your project's history is crystal clear.
Stay tuned for more Git wisdom in the next phase of our Git adventure! ๐๐จโ๐ป
This is not the end more to come Join me in this series and lets connect on LinkedIn
#Git #VersionControl #Coding #DevOps #SimplifyTech