User Tools

Site Tools



Many tips I have been learning to use GIT

Revert commit

# Reset the index and working tree to the desired tree
# Ensure you have no uncommitted changes that you want to keep
$ git reset --hard 56e05fced
# Move the branch pointer back to the previous HEAD
$ git reset --soft HEAD@{1}
$ git commit -m "Revert to 56e05fced"

Recover a deleted file

nicky$: file="filepath"
nicky$: git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"

Ignore files

To ignore files, create a file named .gitignore inside the root directory of your project:

nicky$: touch .gitignore

Afterwards, fill up the file with for example:

*.exe #Every file that has this extension won't be commited
[B][b]in/ #Ignore all files of bin directory that starts either  by Bin/bin
[B][b]in/* #Ignore all subfolders of bin directory


nicky$: git add .
nicky$: git commit -m “Add ignore file”

If it is not take into account, you can reset the git cache:

nicky$: git rm -r –cached .

Note: before the word cached, there are two -

Show remote branches

$ git ls-remote --heads origin


Enter your comment. Wiki syntax is allowed:
git.txt · Last modified: 2019/08/17 22:05 by nicky