Search for a text accross all revision of a file












1















I have a file which contained some text at some point which was then deleted.



I forgot which exact commit and in what branch it existed.



Is there any way to search all revisions of a file accross all the branches and find a commit where file contains specific text?










share|improve this question

























  • git log -p FILE to show the diffenrence (as a patch), then you can easily search the result for the specific text

    – Geoffroy
    Jan 18 at 12:43
















1















I have a file which contained some text at some point which was then deleted.



I forgot which exact commit and in what branch it existed.



Is there any way to search all revisions of a file accross all the branches and find a commit where file contains specific text?










share|improve this question

























  • git log -p FILE to show the diffenrence (as a patch), then you can easily search the result for the specific text

    – Geoffroy
    Jan 18 at 12:43














1












1








1








I have a file which contained some text at some point which was then deleted.



I forgot which exact commit and in what branch it existed.



Is there any way to search all revisions of a file accross all the branches and find a commit where file contains specific text?










share|improve this question
















I have a file which contained some text at some point which was then deleted.



I forgot which exact commit and in what branch it existed.



Is there any way to search all revisions of a file accross all the branches and find a commit where file contains specific text?







git






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 18 at 12:58







Alex Zhukovskiy

















asked Jan 18 at 12:38









Alex ZhukovskiyAlex Zhukovskiy

3,87112785




3,87112785













  • git log -p FILE to show the diffenrence (as a patch), then you can easily search the result for the specific text

    – Geoffroy
    Jan 18 at 12:43



















  • git log -p FILE to show the diffenrence (as a patch), then you can easily search the result for the specific text

    – Geoffroy
    Jan 18 at 12:43

















git log -p FILE to show the diffenrence (as a patch), then you can easily search the result for the specific text

– Geoffroy
Jan 18 at 12:43





git log -p FILE to show the diffenrence (as a patch), then you can easily search the result for the specific text

– Geoffroy
Jan 18 at 12:43












1 Answer
1






active

oldest

votes


















4














For this purpose you can use the -S option to git log:



git log -S'bar' -- foo.rb


This search the text bar in the file foo.rb



if you want to search through all diffs you can do: git log -G'bar' -- foo.rb




When -S or -G finds a change, show all the changes in that changeset, not just the files that contain the change in .




NOTE: This search is casesensitive.



If you add -i you can search case insensitive. Making the complete command:



git log -i -S'bar' -- foo.rb


NOTE 2: This searches only in your current branch.



If you want to search accross all branch you should add the --all flag




Pretend as if all the refs in refs/, along with HEAD, are listed on the command line as .




The complete command will be:



git log --all -i -S'bar' -- foo.rb


The output will be something like this:



$ git log --all -i -S'bar' -- foo.rb

commit 53106e9cd319a2d8f960a3bbf2731acd0699a54f (feature/x)
Author: name <email>
Date: Fri Jan 18 13:59:32 2019 +0100

Added word





share|improve this answer





















  • 1





    It search in current branch history only. E.g. I create another branch where I commit a file with blablablah, then I switch back to master and run the command. git log -S'blablablah' returns nothing, when I'd expect to see branch X, commit 124abcf16

    – Alex Zhukovskiy
    Jan 18 at 12:57













  • You should add the --all option :) i've updated the answer

    – Baklap4
    Jan 18 at 13:00






  • 1





    Also note that if the file was renamed and/or copied, you might look at the -M and -C command-line options.

    – kostix
    Jan 18 at 13:16













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54254217%2fsearch-for-a-text-accross-all-revision-of-a-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














For this purpose you can use the -S option to git log:



git log -S'bar' -- foo.rb


This search the text bar in the file foo.rb



if you want to search through all diffs you can do: git log -G'bar' -- foo.rb




When -S or -G finds a change, show all the changes in that changeset, not just the files that contain the change in .




NOTE: This search is casesensitive.



If you add -i you can search case insensitive. Making the complete command:



git log -i -S'bar' -- foo.rb


NOTE 2: This searches only in your current branch.



If you want to search accross all branch you should add the --all flag




Pretend as if all the refs in refs/, along with HEAD, are listed on the command line as .




The complete command will be:



git log --all -i -S'bar' -- foo.rb


The output will be something like this:



$ git log --all -i -S'bar' -- foo.rb

commit 53106e9cd319a2d8f960a3bbf2731acd0699a54f (feature/x)
Author: name <email>
Date: Fri Jan 18 13:59:32 2019 +0100

Added word





share|improve this answer





















  • 1





    It search in current branch history only. E.g. I create another branch where I commit a file with blablablah, then I switch back to master and run the command. git log -S'blablablah' returns nothing, when I'd expect to see branch X, commit 124abcf16

    – Alex Zhukovskiy
    Jan 18 at 12:57













  • You should add the --all option :) i've updated the answer

    – Baklap4
    Jan 18 at 13:00






  • 1





    Also note that if the file was renamed and/or copied, you might look at the -M and -C command-line options.

    – kostix
    Jan 18 at 13:16


















4














For this purpose you can use the -S option to git log:



git log -S'bar' -- foo.rb


This search the text bar in the file foo.rb



if you want to search through all diffs you can do: git log -G'bar' -- foo.rb




When -S or -G finds a change, show all the changes in that changeset, not just the files that contain the change in .




NOTE: This search is casesensitive.



If you add -i you can search case insensitive. Making the complete command:



git log -i -S'bar' -- foo.rb


NOTE 2: This searches only in your current branch.



If you want to search accross all branch you should add the --all flag




Pretend as if all the refs in refs/, along with HEAD, are listed on the command line as .




The complete command will be:



git log --all -i -S'bar' -- foo.rb


The output will be something like this:



$ git log --all -i -S'bar' -- foo.rb

commit 53106e9cd319a2d8f960a3bbf2731acd0699a54f (feature/x)
Author: name <email>
Date: Fri Jan 18 13:59:32 2019 +0100

Added word





share|improve this answer





















  • 1





    It search in current branch history only. E.g. I create another branch where I commit a file with blablablah, then I switch back to master and run the command. git log -S'blablablah' returns nothing, when I'd expect to see branch X, commit 124abcf16

    – Alex Zhukovskiy
    Jan 18 at 12:57













  • You should add the --all option :) i've updated the answer

    – Baklap4
    Jan 18 at 13:00






  • 1





    Also note that if the file was renamed and/or copied, you might look at the -M and -C command-line options.

    – kostix
    Jan 18 at 13:16
















4












4








4







For this purpose you can use the -S option to git log:



git log -S'bar' -- foo.rb


This search the text bar in the file foo.rb



if you want to search through all diffs you can do: git log -G'bar' -- foo.rb




When -S or -G finds a change, show all the changes in that changeset, not just the files that contain the change in .




NOTE: This search is casesensitive.



If you add -i you can search case insensitive. Making the complete command:



git log -i -S'bar' -- foo.rb


NOTE 2: This searches only in your current branch.



If you want to search accross all branch you should add the --all flag




Pretend as if all the refs in refs/, along with HEAD, are listed on the command line as .




The complete command will be:



git log --all -i -S'bar' -- foo.rb


The output will be something like this:



$ git log --all -i -S'bar' -- foo.rb

commit 53106e9cd319a2d8f960a3bbf2731acd0699a54f (feature/x)
Author: name <email>
Date: Fri Jan 18 13:59:32 2019 +0100

Added word





share|improve this answer















For this purpose you can use the -S option to git log:



git log -S'bar' -- foo.rb


This search the text bar in the file foo.rb



if you want to search through all diffs you can do: git log -G'bar' -- foo.rb




When -S or -G finds a change, show all the changes in that changeset, not just the files that contain the change in .




NOTE: This search is casesensitive.



If you add -i you can search case insensitive. Making the complete command:



git log -i -S'bar' -- foo.rb


NOTE 2: This searches only in your current branch.



If you want to search accross all branch you should add the --all flag




Pretend as if all the refs in refs/, along with HEAD, are listed on the command line as .




The complete command will be:



git log --all -i -S'bar' -- foo.rb


The output will be something like this:



$ git log --all -i -S'bar' -- foo.rb

commit 53106e9cd319a2d8f960a3bbf2731acd0699a54f (feature/x)
Author: name <email>
Date: Fri Jan 18 13:59:32 2019 +0100

Added word






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 18 at 13:01

























answered Jan 18 at 12:43









Baklap4Baklap4

1,62511236




1,62511236








  • 1





    It search in current branch history only. E.g. I create another branch where I commit a file with blablablah, then I switch back to master and run the command. git log -S'blablablah' returns nothing, when I'd expect to see branch X, commit 124abcf16

    – Alex Zhukovskiy
    Jan 18 at 12:57













  • You should add the --all option :) i've updated the answer

    – Baklap4
    Jan 18 at 13:00






  • 1





    Also note that if the file was renamed and/or copied, you might look at the -M and -C command-line options.

    – kostix
    Jan 18 at 13:16
















  • 1





    It search in current branch history only. E.g. I create another branch where I commit a file with blablablah, then I switch back to master and run the command. git log -S'blablablah' returns nothing, when I'd expect to see branch X, commit 124abcf16

    – Alex Zhukovskiy
    Jan 18 at 12:57













  • You should add the --all option :) i've updated the answer

    – Baklap4
    Jan 18 at 13:00






  • 1





    Also note that if the file was renamed and/or copied, you might look at the -M and -C command-line options.

    – kostix
    Jan 18 at 13:16










1




1





It search in current branch history only. E.g. I create another branch where I commit a file with blablablah, then I switch back to master and run the command. git log -S'blablablah' returns nothing, when I'd expect to see branch X, commit 124abcf16

– Alex Zhukovskiy
Jan 18 at 12:57







It search in current branch history only. E.g. I create another branch where I commit a file with blablablah, then I switch back to master and run the command. git log -S'blablablah' returns nothing, when I'd expect to see branch X, commit 124abcf16

– Alex Zhukovskiy
Jan 18 at 12:57















You should add the --all option :) i've updated the answer

– Baklap4
Jan 18 at 13:00





You should add the --all option :) i've updated the answer

– Baklap4
Jan 18 at 13:00




1




1





Also note that if the file was renamed and/or copied, you might look at the -M and -C command-line options.

– kostix
Jan 18 at 13:16







Also note that if the file was renamed and/or copied, you might look at the -M and -C command-line options.

– kostix
Jan 18 at 13:16




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54254217%2fsearch-for-a-text-accross-all-revision-of-a-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre