/git-cheatsheet

Another personal Git Cheatsheet.

Useful GIT’s commands

Get filenames diff between two branches or tag

git diff --name-only tag..master

Reset and conserve files

This command is useful if you want to cancel your last n commits and conserve all the modifications.

git reset --soft HEAD~n

Revert merge and go back to the HEAD version

git reset --merge ORIG_HEAD

n is the number of commit to reset.

Make a patch

Useful commands you use for creating a patch for clients.

Create a zip from a diff filenames

git diff --name-only tag..master | xargs zip name.zip

This command will make a zip file from the diff.

If you want to delete a part of the path you have to do this:

git diff --name-only tag..master | sed "s/project\///" | xargs zip name.zip

project is the part of the path you want to delete.

Playing with branches

Create a branch

git checkout -b branch_name

Switch to a branch

git checkout branch_name

Merge a branch

git merge branch_name

This command will merge branch_name into your current branch. For exemple, if you are on the master, this will merge the selected branch into master.

Delete a merged branch

git branch -d branch_name

Delete a branch even not merged

git branch -D branch_name

Delete a branch on origin

git push origin :branch_name

Tag

Create a tag

git tag tag_name

Push a tag to origin

git push origin tag_name

Delete a tag

git tag -d tag_name

Delete a tag on origin

git push origin :tag_name