frankyonnetti
4/12/2016 - 4:44 PM

#git commands

GIT - commands #git

# ============ list file =================

# show list of files in current commit
$ git show --name-only

# show list of files from a past commit
$ git show --name-only 7cdf78b

# show list of files between commits
$ git diff --name-only 4ce07ee 7cdf78b

# ============= other basic commands ======

# Show HASH for current branch
$ git log -n 1 [branch_name]

# List all existing branches 
$ git branch

# Show information about a remote 
$ git remote show origin

# Download all changes from <remote>, but don‘t integrate into HEAD 
$ git fetch origin

# Download changes and directly merge/ integrate into HEAD
$ git pull origin <branch>

# Force pull
$ git fetch
$ git reset --hard origin/master

# Pull down a branch from remote
$ git branch --track <new-branch> origin/<remote-branch>

# Switch HEAD branch. Can use this to pull a branch form origin
$ git checkout <branch>

# Create a new branch based on your current HEAD
$ git branch <new-branch>

# Disgard unstaged changes
$ git checkout .

# Add (stage) all current changes to the next commit
$ git add --all

# Commit all local changes
$ git commit -am 'This is my message for the commit. . . '

# Merge <branch> into your current HEAD ???
$ git merge <branch>

# Publish local changes on a remote 
$ git push origin <branch>

# Delete a local branch
$ git branch -d <branch>

# Delete a remote branch
# - Note that in most cases the remote name is `origin`
$ git push --delete <remote_name> <branch_name>

# Ignore file permissions in GIT
$ git config core.filemode false

# Get file history for a file
$ git log -- FILENAME

# Delete tag from origin
$ git push --delete origin TAG_NAME

# Git hard rest; force pull
$ git fecth
$ git reset --hard origin/environment/prod
- or -
$ git reset --hard a6d170ff

# Remove obsolete remote branches
$ git remote prune origin

# Show current commit hash
# long
$ git log -1 --format="%H"
# short
$ git log --pretty=format:'%h' -n 1

# Get commit hash
$ git rev-parse HEAD
- or -
$ git rev-parse --verify HEAD

# Exclude files
Add file to: `.git/info/exclude`

# Remove large files from history
# https://stackoverflow.com/a/30274113
$ git filter-branch --tree-filter 'rm -f dir/modules' HEAD
# https://stackoverflow.com/a/7654880
$ git update-ref -d refs/original/refs/heads/master


# Force push
git push origin <your_branch_name> --force

# Who created branch
git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n

- or -

git for-each-ref --format='%(color:cyan)%(authordate:format:%m/%d/%Y %I:%M %p)    %(align:25,left)%(color:yellow)%(authorname)%(end) %(color:reset)%(refname:strip=3)' --sort=authordate refs/remotes