Let's say you have two commits d9e1db9 and 5651067 and want to see what happened between them.
d9e1db9 is the oldest ancestor and 5651067 is the final descendant in the chain of commits.
gitk --ancestry-path d9e1db9 5651067
Imagine you are on the master branch and something is not working as expected (a regression was introduced), but you don't know where. All you know is, that is was working in the last release (which was e.g., tagged or you know the commit hash, lets take old-rel here).
Git has help for you, finding...
$ git reset --hard HEAD^ # discard last commit
$ git rebase --interactive HEAD~5 # rebase last 4 commits
A suffix ^ to a revision parameter means the first parent of that commit object. ^<n> means the <n>-th parent (i.e. <rev>^ is equivalent to <rev>^1).
A...
$ git show HEAD^{/fix nasty bug} # find starting from HEAD
$ git show ':/fix nasty bug' # find starting from any branch
A colon (':'), followed by a slash ('/'), followed by a text, names a commit whose commit message matches the specified regular expression. This name returns the younge...
add: add the specified files on the next commit
addremove: add all new files, delete all missing files
backout: reverse effect of earlier changeset
commit, ci: commit the specified files or all outstanding changes
copy, cp: mark files as copied for the next commit
forge...
When building a custom release track, it's common to keep packages in the /packages directory as git submodules. The following command allows you to fetch all of the latest commits for the submodules in your /packages directory at the same time.
git submodule foreach git pull origin master
Use git revert to revert existing commits, especially when those commits have been pushed to a remote repository. It records some new commits to reverse the effect of some earlier commits, which you can push safely without rewriting history.
Don't use git push --force unless you wish to bring down ...
You cam amend the time of a commit using
git commit --amend --date="Thu Jul 28 11:30 2016 -0400"
or even
git commit --amend --date="now"
If you make a commit as the wrong author, you can change it, and then amend
git config user.name "Full Name"
git config user.email "[email protected]"
git commit --amend --reset-author
Sometimes it happens that a file was being tracked by git, but in a later point in time was added to .gitignore, in order to stop tracking it. It's a very common scenario to forget to clean up such files before its addition to .gitignore. In this case, the old file will still be hanging around in th...
Git shortlog is used to summarize the git log outputs and group the commits by author.
By default, all commit messages are shown but argument --summary or -s skips the messages and gives a list of authors with their total number of commits.
--numbered or -n changes the ordering from alphabetical (...
.git/hooks/pre-commit
#!/bin/sh
if [ -s pom.xml ]; then
echo "Running mvn verify"
mvn clean verify
if [ $? -ne 0 ]; then
echo "Maven build failed"
exit 1
fi
fi
A process can (try to) send a signal to any other process using the kill() function.
To do so, the sending process needs to known the receiving process' PID. As, without introducing a race, a process can only be sure of its own PID (and the PIDs of its children) the most simple example to demonstra...
To view difference between two branch
git diff <branch1>..<branch2>
To view difference between two branch
git diff <commitId1>..<commitId2>
To view diff with current branch
git diff <branch/commitId>
To view summary of changes
git diff --stat <branch/com...
Before making a pull request, it is useful to make sure that compile is successful and tests are passing for each commit in the branch. We can do that automatically using -x parameter.
For example:
git rebase -i -x make
will perform the interactive rebase and stop after each commit to execute mak...