How To Find Commits With Code Containing a String
erics, February 7th, 2020 |
1 |
git log --pickaxe-regex -p --color-words -S "theSearchString" |
|
erics, February 7th, 2020 |
1 |
git log --pickaxe-regex -p --color-words -S "theSearchString" |
erics, February 7th, 2020 First, get on the branch that you know already has the commits you are looking for:
|
1 |
git checkout theBranch-1234 |
Copy-and-paste the commit(s) you want:
|
1 |
git log |
~or~
|
1 |
git log -p |
Optionally, display the code changes for a visual confirmation:
|
1 |
git show {one or more commit ID's} |
Finally, extract the list of branches that contain the desired commits:
|
1 2 |
git branch --contains CommitID-A git branch --contains CommitID-B |
Example:
|
1 2 3 |
git log git branch --contains 097e1859f248a7aa5e148a2a946be3e360030095 git branch --contains 24339549f9f1920a33f721d3faa2538c8ba5d249 |
erics, January 30th, 2020 Recently, I wanted to see the “origin” of the git repository I was working in. The command is: git remote -v For example:
|
1 2 3 |
theUser@theHost$ git remote -v origin git@localhost:/volumes/data/git/thePlugin.git (fetch) origin git@localhost:/volumes/data/git/thePlugin.git (push) |
erics, December 2nd, 2019 Not pushed + most recent commit:
|
1 |
git commit --amend |
erics, June 3rd, 2019 To display the filenames included in each commit, just add the –name-only argument to git log:
|
1 |
git log --name-only |
erics, May 31st, 2019 Quickref: How to Remove a file from the staging area
|
1 |
git rm --cached {fileName(s)} |
The Story Recently, I accidentally added some files to git’s pre-commit phase, i.e.:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
shell> git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: good1.xml new file: good2.xml new file: bad1.xml new file: bad2.xml modified: good3.xml modified: bad3.xml |
For example, here is how to handle the above situation:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
shell> git rm --cached bad1.xml bad2.xml bad3.xml shell> git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: good1.xml new file: good2.xml modified: good3.xml Untracked files: (use "git add <file>..." to include in what will be committed) bad1.xml bad2.xml bad3.xml |
To better understand, here are the phases/states/stages that git uses: Untracked – when a file is first created, git […]
erics, March 18th, 2019 |
1 2 3 |
git log {path_and_file} git checkout {commit_hash} -- {path_and_file} git checkout 8c7eae3f518bb7fd98eb6e8344270f02065d83ee -- myFile.txt |
~or~
|
1 |
git checkout master -- theSubDir/theFile.json |
erics, January 31st, 2018 Rename the old branch locally: git branch -m oldBranch newBranch Delete the old branch remotely: git push origin :oldBranch Push up the new branch, and make the local branch track with the new remote branch: git push –set-upstream origin newBranch
erics, October 19th, 2017 Git does not download all branches unless you tell it to. Until then, they are ‘remote’ branches. Use -r to list remote branches: git branch -r git fetch –all git pull –all If you see this error: fatal: The current branch CT-37 has no upstream branch. Push the current branch and set the remote as […]