Skip to content

Cronos87/git-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 

Repository files navigation

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

n is the number of commit to reset.

Revert merge and go back to the HEAD version

git reset --merge ORIG_HEAD

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.

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

Reset a branch to the origin state

git fetch origin
git reset --hard origin/branch_name

Show merged branches

git branch --merged

Show merged branches in the current branch.

Show unmerged branches

git branch --no-merged

Show unmerged branches in the current branch.

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

Divers

Order tags by creation date

git config --global tag.sort version:refname

Add an empty directory

To add an empty directory, you have to create an empty file named .gitkeep and then commit this file.

Find who create a file

git log --diff-filter=A -- filepath

Remove all same files

find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch

About

Another personal Git Cheatsheet.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •