A reminder of usefull git commands.
Web resources
General purposes
- A simple git guide by Roger Dudler.
- My Git Workflow by Oliver Steele.
Git diagram
Git commands i’m used to use
I was wrong on some commits AND already pushed (discard all updated files)
To see all what happened (history) on the current branch
$ git log --graph --decorate --all
To go back just before a particular commit (and to loose all the work made after) do the following
$ git reset <on commit i want to go back number >
To push on the current branch in the remote repository (which could have more recent commits: those we have just deledted above)
$ git push -f (--force)
Rolling back a local commit NOT already pushed
To revert the latest commit and discard changes in the committed file
$ git reset --hard HEAD~1
To revert the latest commit but retain the local changes (on disk)
$ git reset --soft HEAD~1
This later command will take me to the state I would have been if I did
git add
before
To unstage the files after that do:
$ git reset
Now I can make more changes before adding and then committing again.