Skip to content

Instantly share code, notes, and snippets.

@macmladen
Last active September 11, 2018 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macmladen/3a71b6d1c4861f9cb185 to your computer and use it in GitHub Desktop.
Save macmladen/3a71b6d1c4861f9cb185 to your computer and use it in GitHub Desktop.
Git hints, .gitconfig and .gitignore files - should be moved to 'dotfiles' repo
[user]
name = MacMladen iMac
email = mladen@bluefish.rs
[color]
ui = on
[core]
excludesfile = /Users/mladen/.gitignore_global
whitespace= fix,-indent-with-non-tab,-indent-with-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore_global
[difftool "sourcetree"]
cmd = opendiff \"$LOCAL\" \"$REMOTE\"
path =
[mergetool "sourcetree"]
cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
trustExitCode = true
keepBackup = FALSE
[alias]
df = !git diff --no-prefix && git diff --staged --no-prefix
clear = reset --hard
st = status
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
co = checkout
con = checkout -b
ci = commit -am
c = commit -m
br = branch
ls = branch -a
rs = remote show origin
lgs = log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit --date=short --no-merges --committer MacMladen
pr = pull --rebase
[push]
default = simple
[push]
default = current
[filter "lfs"]
clean = git-lfs clean %f
smudge = git-lfs smudge %f
required = true
### Put application level patterns to ignore first then procede to more general ones.
## Frontend build files
# Ignore Compass temp & devel files
.sass-cache
*.css.map
## Drupal ignores
# Ignore configuration files that may contain sensitive information.
sites/*/settings*.php
# Ignore paths that contain user-generated content.
sites/*/files
sites/*/private
# Modules and themes used for testing or dev.
sites/all/modules/contrib/styleguide/
sites/all/modules/contrib/seo_checklist/
sites/all/modules/contrib/checklistapi/
sites/all/modules/contrib/examples/
# Ignore CSS files - generate them
sites/all/themes/*/css/
### The section below can be used for ~/.gitignore_global
### that ignores files by pattern for all git controlled projets.
###
### ! be careful with global ignore it may not be valid for all your projects !
###
### Comment out or delete patterns that you do not want to be ignored.
# Ignore backups and archives
*~
*.bak
*-bak
*.sql
*.sql.gz
*.tar
*.gz
*.tgz
# Mac OS X specific files
.DS_Store
._*
.AppleDouble
.LSOverride
Icon
# Files that might appear on external disk
.Spotlight-V100
.Trashes
# Thumbnails
Thumbs.db
# Ignore CTags
.tags*
# IDE files
.buildpath
.project
.settings
.metadata
.cache
.idea
*.sublime-*
*.esproj
.directory
# Server files
awstats-icon
awstatsicons
icon
# .htaccess
# .htpasswd
# htusers
# Phpmyadmin
phpmyadmin
# Dev
FirePHPCore

Git hints collected

The easiest way would be to find the head commit of the branch as it was immediately before the rebase started in the reflog...

git reflog

and to reset the current branch to it (with the usual caveats about being absolutely sure before reseting with the --hard option).

Suppose the old commit was HEAD@{5} in the ref log

git reset --hard HEAD@{5}

You can check the history of the candidate old head by just doing a git log HEAD@{5}.

If you've enabled per branch reflogs you should be able to simply do git reflog branchname@{1} as a rebase detaches the branch head before reattaching to the final head. I would double check this, though as I haven't verified this recently. You can do this by adding:

[user]
    logallrefupdates=true

Get rid of the crap in repo without merge

This will revert the current branch to the exact same state as the remote repository, removing all the files and directories not present on remote.

git reset --hard origin/{branch}
# Note: Any changes not committed will be lost.
git branch newbranch      # Create a new branch, saving the desired commits
git checkout oldbranch    # Return to old to reset it
git reset --hard HEAD~3   # Move master back by 3 commits (GONE from master)
git checkout newbranch    # Go to the new branch that still has the desired commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment