Git: Search for text in all branches
To find a version containing the regular expression foo
in the history of any branch:
git grep foo $(git rev-list --all)
You may also limit the search to a file extension, e.g. Ruby files (.rb
) like this:
git grep foo $(git rev-list --all) -- *.rb
Related cards:
Git: See all unpushed commits or commits that are not in another branch
If you need to find out which of your local commits are not on the remote server do this:
git cherry -v
The -v
option prints out the commit messages. Without it you will see only the SHA1 codes.
You may also compare against another (upstr...
Recommended Git workflow for feature branches
This is a guide on how to effectively use Git when working on a feature branch. It is designed to get out of your way as much as possible while you work, and ensure you end up with clean commits in the end.
**We assume you are the only person wor...
Git: Advisory for cherry-picks to production branches
We often have a separate production branch that lags a bit behind the more cutting edge main branch. Sometimes you want to move some, but not all commits from main to production. This can be done with a git cherry-pick
.
However, this ma...
Git: Merge a single commit from another branch
This is called "cherry-picking".
git cherry-pick commit-sha1
Note that since branches are nothing but commit pointers, cherry-picking the latest commit of a branch is as simple as
git cherry-pick my-feature-branch
**Be aware that c...
Duplicate a git repository with all branches and tags
In order to clone a git repository including all branches and tags you need to use two parameters when cloning the old and pushing to the new repository respectively:
git clone --bare http://example.com/old-repo.git
cd old-repo
git pu...
Bookmarklet to facilitate generating new git branches for PivotalTracker Stories
This bookmarklet grabs a PivotalTracker story title, transforms it into a valid git branch name and automatically prepends your initials and an optional abbreviation (for better tab completion). It will output the following formats:
If you cancel...
Squashing several Git commits into a single commit
This note shows how to merge an ugly feature branch with multiple dirty WIP commits back into the master as one pretty commit.
Squashing commits with git rebase
What we are describing here will destroy commi...
Git diff a file with another revision (or branch)
git diff commit_hash -- path/to/file
Provide any commit hashes or branch names like "master
" for commit_hash
.
Scoping a sunspot solr search by text using a string field
Assuming the following sunspot setup of the post class:
class Post < ActiveRecord::Base
searchable do
text :title
string :state
integer :category_ids
end
end
In Sunspot you can scope your search via th...
Git: Show commits that have touched specific text in a file
If you want to find the commits that touched a specific text in a file, use
git log -S 'text in the code' -- path/to/file
If you use tig you may run a similar command to get a navigatable list of affected files:
tig -S'text ...