Skip to content

Git cheatsheet

Ignore content

Ignore content of a folder but keep the folder
Add a .gitignore
*
!.gitignore

Branches

Rename current branch
git branch -m \<new-name\>
Rename another branch
git branch -m \<old-name\> \<new-name\>

Commits

Find in git log
git log \--all \--grep=...
Find commits that changed a file
git log --- \[filename\]
See changes (diff) of a commit
git diff COMMIT\^!
See changes (diff) between commits of a file
git diff SHA1\^ SHA1 path/to/file
Remove last commit

git reset \--hard HEAD\~1

:::: caution ::: title Caution :::

HEAD~1 is a shorthand for the commit before head. Alternatively you can refer to the SHA-1 of the hash you want to reset to. Note that when using --hard any changes to tracked files in the working tree since the commit before head are lost. ::::

:::: tip ::: title Tip :::

If you don't want to wipe out the work you have done, you can use --soft option that will delete the commit but it will leave all your changed files \"Changes to be committed\", as git status would put it. ::::

Submodules

Multiple branches of the same repository

It is possible to add the same repository as submodule in different locations.

It is also possible to let a submodule follow a specific branch.

git submodule set-branch -b version-2.01 lib/standard/2.01

This makes it possible to have each IATI version under a separate location, all available at the same time.