leponceau.org

Programming And Stuff, You Know The Thing…

Git Cheat Sheet

Posted at — Oct 24, 2017

Table of Contents

show change history/log with content diffs

git log -p

show changes filenames in log

git log --name-only
git log --name-status

undo local commit

without destroying local changes

git reset --mixed

create a tag

git tag 1.2.0
git push origin 1.2.0

delete a tag

git tag -d $tag
git push origin :$tag

roll back history

git reset --hard $newLatestRev
git push -f

This does not affect tags.

add changes to latest commit

git commit --amend
git push -f

merge/remove past commits

git rebase -i $revBefore
git push -f

sub-modules

# fetch in checked out project
git submodule update --init --recursive
# update
git submodule update --recursive --remote
# clone/checkout with sub-modules
git clone --recursive https://..

create a “master” repository from another existing master repository

git clone --bare https://.../mystuff.git mystuff.git

update including all tags

git pull --tags

clean up local checkout (delete/revert local changes)

# test:
git clean -d -x -n
# delete everything that's not part of the repository:
git clean -d -x -f
# revert changed files:
git checkout -f

merge upstream changes

git remote add upstream https://github.com/krenfro/fannj.git
git pull upstream master

reset master to upstream

http://stackoverflow.com/questions/5916329/cleanup-git-master-branch-and-move-some-commit-to-new-branch

# Make a new branch to hold stuff

$ git branch old_master

# Send to remote for backup (just incase)

$ git checkout old_master
$ git push origin old_master

# Reset local master to the commit before you started modifying stuff

$ git checkout master
$ git reset --hard 037hadh527bn

# Merge in changes from upstream master

$ git pull upstream master

Now DELETE master on remote repo.

On github this won’t work without first going into the admin section for the fork and setting the default branch to something other than master temporarily as they try and protect you from blowing stuff away.

$ git push origin :master

# And recreate it

$ git push origin master

On github you should now set the default branch back to master

diffs and patches

To dump a diff covering submodule paths:

git diff --submodule=diff <path> > ../1.patch

Then:

git apply ../1.patch