0

I have a text file that I'd like to track changes with. It's a file that stores values (as well as strings and arrays) and has the following format for its entries:

NAME: some_name
  UNIT: some_unit
  ...
  VALUE: 10
  ...
END

I've setup a repository to track changes on this file BUT now I would like to understand the change history of an entry like some_name.

I think this would be similar to understanding the change history of a function, where the user would like to understand the history of the entire function between various revisions.

I've tried the method described here with several attempts like:

git log -L '\bsome_name\b', '\bEND\b':config.txt

fatal: invalid object name '\bEND\b'.

also from here I've tried:

git log -p | grep '(\bsome_name\b)(.|\s)*?(\bEND\b)'

...which returns nothing.

UPDATE 20240818: Further attempts:

  • Defined a custom hunk-header and tried using git log -L:some_name:config.txt. This does work for some entries but does not find other entries, similar to git log -L'/some_name/','/END/':config.txt
  • using git log -p -W >> test.txt I can manually inspect the output and see that the entries that are not found by the above methods are indeed there.

The answer provided by @phd should work and yet it ignores some entries.

1
  • '-L/^NAME: some_name$/,/^END$/:config.txt', also see here, It's hard to help you understand what's failing when you don't show what's failing. Commented Aug 19, 2024 at 16:51

2 Answers 2

2

The syntax is git log -L/start_re/,/end_re/:file, no spaces inside. Git uses POSIX regex syntax that doesn't support \b word boundary. Try this:

git log -L'/some_name/','/END/':config.txt
Sign up to request clarification or add additional context in comments.

9 Comments

with this i get fatal: -L parameter 'some_name' starting at line 1: No match
@jayveesea Just tried — works for me. You need to show something real, not just error message. minimal reproducible example, please.
not sure how to provide an mre here, unfortunately this is not on github nor open source to be cloned, so complete and reproducible is a challenge. that said, i think your hint on POSIX regex may lead somewhere.
@jayveesea Create a small public repo and push it to GitHub for us to clone. One small file, a few commits, and an example of failed git log -L command.
also created a test repo and this kinda works but starts to break when the entry is moved around. many changes were made to some_name but it only detects a recent one now.
|
2

Look up the line numbers of the first line and the last line of the block of text you want to look at in the currently checked-out file. Then:

git log -L123,157:config.txt

(Obviously, replace the numbers by those that you found.) Note that there are no blanks in the command line argument.

3 Comments

thx for info, unfortunately this config file has entries that are occasionally removed or added, so position varies
@jayveesea That does not matter, because Git knows about the changes. Just pick the line numbers in the file that is currently checked out.
it does kinda work but when there's a major change in position it looses track and starts looking at the wrong thing. if there wasn't such drastic changes to my config file this would work nicely. thx!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.