Git Product home page Git Product logo

useful-git-command's Introduction

------------------------------------------------
You can add any commands or improve existing one
However, you must follow the current pattern is:

# THE_GIT_COMMAND_EXPLANATION
THE_GIT_COMMAND_1
THE_GIT_COMMAND_2
...
------------------------------------------------

Commits
==============
# Update a commit
git commit --amend

# Reset last commit
git reset --soft HEAD^


Branches
==============
# To cherry-pick
git checkout branchname
git log
> Get the sha1
git checkout master
git cherry-pick the_sha1

# Update your branch from master
git checkout ma_branche
git rebase master

# Rebase
git pull --rebase origin master 

# Resolve conflict on a rebase
git add resolvedFile
git rebase --continue 
OR
git rebase --abort

# Merge 2 branches
git checkout master
git merge branch_name

# Remove obsoletes local branches
git remote prune origin

# On message 'your branch is 2 commits...'
git fetch --depth=HEAD


Differences
==============
# View changes in a file
git log -p FILE

# View changes between head and a commit
git diff SHA1

# View changes between 2 commits
git diff SHA1 OTHER_SHA1

# View files that have changed between 2 branches
git diff --name-status master..branch


Revert your changes
==============
# Revert a file
git checkout -- FILE 

# Remove a file from staging area
git reset FILE

# Reset your updates
git reset --hard HEAD

# Reset to master on origin
git reset --hard origin/master

# Cancel a commit
git rebase -i HEAD~2
git mergetool
git rebase --continue

# Remove a tag
git tag -d TAGNAME
# if tag is already pushed, you should push the removal
git push origin :refs/tags/TAGNAME

Bissect
==============
# begin a bissection
git bissect start
git bissect bad COMMIT
git bissect good COMMIT

# then, if you can, automate it
git bissect run COMMAND

# after, you may log results
git bisect log > bisect_log.txt

# and later, you may replay a log result
git bisect replay bisect_log.txt


Update all local projects
==============
#!/bin/bash
command='git pull'
for i in `ls -d */`; do
   echo Udating ${i}
   cd ${i}
   $command
   cd ..
done

useful-git-command's People

Contributors

ulrich avatar paulgreg avatar

Watchers

James Cloos 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.