GithubHelp home page GithubHelp logo

git-useful's Introduction

git-useful

a collection of incredibly useful git commands

Table of Contents

Add

add files interactively

git add <file> --patch

# working example
git add . --patch

Very useful when you need to commit different lines of a file. See more at the docs for Interactive Mode.

Log

shows commit frequency for each user in the repo

git log --format='%an' . | \
    sort | uniq -c | sort -rn | head

source: http://mislav.uniqpath.com/2014/02/hidden-documentation/

pretty log (one line with graphic and colors)

git log \
  --graph \
  --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'

logs commits that added or removed a certain keyword

git log -S '<keyword>'

source: http://mislav.uniqpath.com/2014/02/hidden-documentation/

lists already-merged branches

git branch --merged [<branch>]

# working examples
git branch --merged master

# in the current HEAD
git branch --merged

source: http://stevenharman.net/git-clean-delete-already-merged-branches

Diff

diff word-by-word

git diff --word-diff

source: http://idnotfound.wordpress.com/2009/05/09/word-by-word-diffs-in-git/

short infos about changes in a commit

git diff-tree --no-commit-id --shortstat -r <commit-hash>

# working example
git diff-tree --no-commit-id --shortstat -r HEAD

show changed files in a commit

git diff-tree --no-commit-id --name-only -r <commit-hash>

# working example
git diff-tree --no-commit-id --name-only -r HEAD

If you want a more detailed version, run with the --stat, or --numstat or --dirstat flags instead of --name-only.

source: http://stackoverflow.com/questions/424071/list-all-the-files-for-a-commit-in-git

list every changed file between two commits

git diff --name-only <commit-hash> <commit-hash>

# working example
git diff --name-only HEAD~3 HEAD

source: http://stackoverflow.com/questions/1552340/git-show-all-changed-files-between-two-commits

show modifications in a file in a commit

git diff <commit-hash>~1..<commit-hash> [<file>]

# working example
git diff HEAD~1..HEAD

You can optionally add a file name to show only changes in a specific file.

show files with conflicts

git diff --name-only --diff-filter=U

source: http://stackoverflow.com/questions/3065650/whats-the-simplest-way-to-git-a-list-of-conflicted-files

Branch

deletes already-merged branches

git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

source: http://stevenharman.net/git-clean-delete-already-merged-branches

add new branch and switches to this branch

git checkout -b <branch>

source: http://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

Misc

sync fork

# Requires an "upstream" remote, pointing to original repo
# e.g. `git remote add upstream [email protected]:user/repo.git`
git fetch upstream; git checkout master; git rebase upstream/master

source: https://help.github.com/articles/syncing-a-fork

assume file as unchanged

git update-index --assume-unchanged <file>

# working example
git update-index --assume-unchanged .

undo assume file as unchanged

git update-index --no-assume-unchanged <file>

# working example
git update-index --no-assume-unchanged .

source: http://stackoverflow.com/questions/17195861/undo-a-git-update-index-assume-unchanged-file

list files assumed as unchanged

git ls-files -v|grep '^h'

source: http://stackoverflow.com/questions/17195861/undo-a-git-update-index-assume-unchanged-file

Others

More than one line command useful things

git-useful's People

Contributors

hugooliveirad avatar raphaelfabeni avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.