Ich bin Deborah.
Schaut euch meine Arbeiten
an oder lest meinen Blog.

git cheat sheet

(English) Some commands I repeatedly had to lookup when dealing with git and github.

View history [source]

  • Simple log:git log
  • Last two commits:git log -2
  • Last two commits with changes:git log -p -2
  • Commit list with hash:git log --pretty=oneline
  • Commit ancestry graph by branches:git show-branch

Committing changes

What has been changed?

  • unstaged files:diff file
  • staged files:diff --staged file

Add only parts of file to stage

  • Interactive patching of file [source] git add --patch file
  • When using the above command, the hulks are somethimes too big and the edit hulk option too difficult to handle. I therefore prefer git gui [source]:sudo apt-get install git-guijust run this command before staging changes:git gui

Moving untracked changes to stash

When you want to apply a merge or update your repository and you get the following message: „error: Your local changes to the following files would be overwritten [..] Please, commit your changes or stash them before you can merge.“ This is how to use stash:
git stash
git stash list
git stash apply

Undo changes, remove changes, reset files..

Remove file from stage but keep changes [source]

  • git reset HEAD file

Reset all changes since last commit

  • git reset --hard HEAD

Reset all changes since second last commit

  • git reset --hard HEAD~1

Restore added changes removed with the above command [source]

  • git reset --hard HEAD@{1}

.gitignore

Ignore files only locally without using .gitignore [source]

To ignore files without adding them to a possibly syncronised .gitignore file, add the files to info/exclude.

Add tracked files to .gitignore [source]

  • git rm --cached path/file
    echo 'path/file' >> .gitignore

Modify commits

Split previous commit [source]

  • git rebase -i HEAD~3..where 3 is the number of commits you have to go back for the commit you want to split. The number can also be higher. You get into an edit mode where you see the last commits with the prefix „pick“. Change that to „edit“ for the commit you want to split.
  • git reset HEAD~
  • Commit multiple separate changes
  • git rebase --continue

Add changes to older commit [source]

  • git add my_fixed_files
    git commit --fixup=OLDCOMMIT
    git rebase --interactive --autosquash OLDCOMMIT^

Branches / forks

Renaming branch [source]

  • git branch -m old_branch new_branch
    git push origin :old_branch
    git push --set-upstream origin new_branch

Adding remote information to fork (before syncing) [source]

  • git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
  • Check with git remote -v

Syncing a fork [source]

  • git fetch upstream
    git checkout master
    git merge upstream/master
    git push

Working with remote branch of coworker [source]

  • Pull branch:git remote add coworker git://path/to/coworkers/repo.git
    git fetch coworker
    git checkout --track coworker/foo
  • Update branch:git checkout foo
    git pull

Creating branch with current staged changes [source]

  • Unstage added changes:git reset --soft HEAD~1
  • Create new branchgit checkout -b newBranch

Deleting branches [source]

  • Local branches:git branch -d the_local_branch
  • Remote branches:git push origin :the_remote_branch

Sag etwas

Deine email-Adresse wird nicht veröffentlicht.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Artikel zum Thema "Blog":

How to print an invisible IR marker using a standard printerQuick, Draw! Generierte Zeichnungen, Teil 2(English) The Art of CodingImperfekte MandalasHerbstblätterFarbexplosion #25 Jahre KAZOOSH!FarbexplosionUbuntu 15.10, MongoDB und node.jsSpeed of Fencing Remixgit cheat sheetFraktaleofxSortableListHäkeln: Haarband mit JeansknopfWandmalen zu Marias GeburtstagLinux / Ubuntu + Serato Vinyl Control System + Pure DataWicket-Bootstrap – Navbar und Pageparameters – aktives Item setzenLinux Console MerkzettelCrawling Traces @Deutscher Multimediapreis mb21Crawling Traces History Viewernew.livestream.com unter Ubuntu mit VLC abspielenCrawling Traces at Hechtfest / hechtgruenLinksammlung: Datensicherheit, soziale Netzwerke und sicheres MailingFix: VMware Player Crash unter Ubuntu 13.04Xubuntu: Wenn Dockbarx Thunar oder das Terminal nicht startet.Ubuntu 12.10, libwebsockets and OFSetting up Meteor with Ubuntu 12.10 on an NTFS share partitionWebauftritt: KAZOOSH!Zwischenstand IsolinienDas Scheunentor wird buntSkype auf Ubuntu 10.10 oder 11.04 64bitElitebook 8440p vs UbuntuKryptografie & Datensicherheit – NotizenRandom Compilation IIRandom Compilation IAll You Can Eat in DresdenWebauftritt: ESE 2010