List all the commits and the affected files:
git log --name-status
List all commits and their hashtag:
git rev-list --all --pretty=oneline
Delete from the local repository all files that were locally deleted without using the git rm
command:
git ls-files -d -z | xargs -0 git update-index --remove
Set the local <branch>
to track the <remote/branch>
:
git branch -u <remote/branch> <branch>
Set a different push URL for a remote repository:
git remote set-url --push <remote> <URL>
git remote -v # to check the change has correctly been applied
Show the local branches tracking information:
git branch -vv
Update all submodules recursively, and init them if necessary:
git submodule update --init --recursive
The goal is to do something like:
A--B--E--F (master)
A--B--C--D--E--F (master) => \
C--D (topic)
- Create the branch, ending at the desired commit:
git branch <topic> D
- (a) Rebase interactively
master
, starting afterB
:
git rebase -i B
- (b) Instead of an interactive rebase, it's possible to use the
--onto
option. In this example it makes the commitB
take the place ofD
inmaster
, skipping the in-between ones.
git rebase D --onto B
To get a specific file as it was in a specific commit (eg. HEAD
) and cancel its working dir changes:
git checkout <commit> <file.ext>
To restore the whole repository as it was in a spcific commit (eg. HEAD^
):
git reset --hard <commit>
To do the same as previously, but keep the local changes and just reset the
index use --soft
instead.
To see the history of the local repo (and the hash of a lost commit):
git reflog
To keep a clean history and revision graph don't use the command git subtree
.
git remote add plugin ../remotes/plugin
git fetch plugin
git read-tree --prefix=vendor/plugins/demo -u plugin/master
git commit -m "Added demo plugin subtree in vendor/plugins/demo"
git fetch plugin
git merge -s subtree --squash plugin/master
git commit -m "Updated the plugin"
Source: medium.com
To filter out the subfolder from the rest of the files in the repository, run:
git filter-branch --prune-empty --subdirectory-filter <folder-name> <branch-name>
with:
<folder-name>
: The folder within your project that you'd like to create a separate repository from.<branch-name>
: The default branch for your current project, for example,master
.
Source: help.github.com
To update a local repo (the local commits will be merged, creating a merge commit):
git pull
A--B--C (origin/master) A--B--C--E (master)
\ => \ /
D (master) -D-
To update a local repo, and prevent a merge commit (doing so, the rebased commits must not have been pushed to a public repository; if they have the subsequent pushes must be done withe the --force
flag):
git pull --rebase
A--B--C (origin/master) A--B--C (origin/master)
\ => \
D (master) D' (master)
Add the following in the repo.git/hooks/post-update
file:
echo
echo "===== Pulling changes into live server ====="
echo
cd /var/www/gregseth.net
unset GIT_DIR
git pull origin master
Run the following command, replacing <path/to/the/file>
with the path to the file you want to remove, not just its filename. These arguments will:
- Force Git to process, but not check out, the entire history of every branch and tag
- Remove the specified file, as well as any empty commits generated as a result
- Overwrite your existing tags
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch <path/to/the/file>" \
--prune-empty --tag-name-filter cat -- --all
Source: help.github.com
Here's a basic configuation file:
[alias]
ci = commit
co = checkout
df = diff
rv = rev-list --all --pretty=oneline
ls = ls-files
ign = ls-files -o -i --exclude-standard
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
[status]
submoduleSummary = true
[color]
ui = true
[push]
default = current
Just add a .gitignore
file at the root of the project folder.
# Visual studio
*.user
*.suo
*.ncb
*.pdb
*.idb
*.aps
Deleted
# Eclipse
.metadata
.settings
# Source safe
*ssc
# Temporary files
tmp
temp
obj
*.bak*
*.out
_*
*.swp
~$*
# Output files and binaries
*.exe
*.lib
*.dll
*.a
*.so
Exec
out
bin
# Project specific