Git is the most commonly used version control system. Git tracks the changes you make to files, so you have a record of what has been done. Git also makes collaboration easier. So regardless of weather you write code that only you will see, or work as part of a team, Git will always be useful for you. So today I am gonna show you 6 best hacks to make working with git easier. These hacks can be a life saver......XD.
1. Modify the most recent commit
git commit --amend
The git commit --amend command is a conventional way to modify the most recent commit. It lets you combine staged changes with the previous commit instead of creating an entirely new commit.
2. Find branch(s) by commit
git branch --contains
If you want to track the remote-tracking branches you should add the -r option. For tracking both the local and remote-tracking branches, use the -a option.
3. Remove file from last commit
git rm --cached than git commit --amend
Let's say you committed a file by mistake. You can quickly remove that file from the last commit by combining the rm and commit --amend commands.
4. Rename branch locally
git branch -m old-name new-name
If you want to rename branch locally, you can write this command in git bash where old-name is the current name of the branch and new-name is the name you want to change.
5. What changed in a span of time
git whatchanged -since='2 weeks ago'
This command will show a log with changes introduced by each commit from last two weeks.
6. Time travelling using GIT
git reflog
It shows the list of all the things you've done so far.
The reference in the orange circle is index value. If you want to go back to any point in the history, run the below command, replacing {index} with that reference.
git reset HEAD@{index}
I hope this was helpful.