Taking the chance to work in a team environment with different developers, I’ve faced many times a lack of documentation for everyday Git commands, which personally define mandatory to avoid mess.
To be clear, these occurring errors have been dictated by a change of OS which I usually work with, from Windows to Mac OS and so then from a Git UI usage to a command line usage. As you could imagine it’s quite hard at the beginning to keep track of modification, since the 2 methods are pretty different.
Consequentially to what above, one of the commands which I appreciated the most, it’s the
amend one. It allows you to add files or edit the comment to your commits.
Add file without edit prompt to the last commit:
$ git add #namefile
$ git commit --amend --no-edit
Modifying the comment:
$ git commit --amend
Now there’s 2 way to push these modifications and are related to local commit only or to remote. If you have the commit locally, then you can simply push. Whenever you want to modify something already pushed to remote, then you will required to force it, since the branch do not match:
$ git push origin NAMEBRANCH --force
A very big not about this: pushing in this way you will override any modification made by anyone else, so unless you work alone, it’s preferred to be done while you work on your branch.
An analogue scenario for mistakes remedy is the
reset command. I usually use this when I want to avoid multiple and useless commits, them merge them together. Another case can be if your hotfix cant be applied or your last commit has broken something and you prefer to reset all the modifications.
To remove the last commits and remove the modifications
$ git reset --hard head~1
To remove the last commits and keeping the modifications, usually for merge or fix them
$ git reset --soft head~1
As in the previous case, to way to push will change if the modification is local or remote.
If you have to handpick too many commits separately and all together or if someone interrupt your SCRUM session for a modification, the command line could probably require too much time even after you become very proficient with Git.
Technically talking, it’s a GUI for Git, which can be launched simply running a command inside your project. I usually prefer to run it in a second terminal due to log spam.
I hope you will found these suggestions clear and helpful just have been for me!