Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

-1 votes
2 answers
188 views
how to filter git commits only if certain directories were changed
I need to filter commits based on directory changes, for example I need to get a list of commits only if the commit made a change in a certain directory. I have tried the path filter glob option mentioned below. but this will include any commit that had a change in the specified directory even if an...
I need to filter commits based on directory changes, for example I need to get a list of commits only if the commit made a change in a certain directory. I have tried the path filter glob option mentioned below. but this will include any commit that had a change in the specified directory even if any other file was changed as part of the commit. git log --pretty=format:'%H %s' -- \apps/web*/* I need to find a way so that only commits that specifically change files in those directories and no other changes are filtered out.
xerxes (359 rep)
May 8, 2025, 12:02 AM • Last activity: May 8, 2025, 10:40 AM
3 votes
7 answers
545 views
sed (or awk): print captured group or placeholder if it doesn't exist
So since GitHub removed the insights tab for non-premium accounts, I'm trying to locally list insertions and deletions to my git repository per day. I figured out this way of printing what I want: ```sh git log --pretty="@%ad" --date=short --shortstat | tr "\n" " " | tr "@" "\n" ``` That produces th...
So since GitHub removed the insights tab for non-premium accounts, I'm trying to locally list insertions and deletions to my git repository per day. I figured out this way of printing what I want:
git log --pretty="@%ad" --date=short --shortstat |  tr "\n" " " | tr "@" "\n"
That produces this kind of output:
2024-06-13   7 files changed, 400 insertions(+), 406 deletions(-) 
2024-06-12   3 files changed, 145 insertions(+) 
2024-06-12   5 files changed, 638 deletions(-) 
2024-06-12   1 file changed, 1 insertion(+), 1 deletion(-)
Notice the plurals in file(s), insertion(s) and deletion(s). Another problem is that a commit might not have insertions or deletions (or both, but let's ignore this case). So I'm almost there, I just need to extract the date, insertions and deletions and group by date. That will produce some sort of "work done per day" graph. I made this regex to capture the fields dealing with all the optionals:
-regex
/^([0-9]{4}-[0-9]{2}-[0-9]{2})\s{3}[0-9]+\sfile(s)?\schanged,\s(([0-9]+)\sinsertion(s)?\(\+\))?(,\s)?(([0-9]+)\sdeletion(s)?\(\-\))?\s$/gm
Now I need to get the 1st, 4th and 8th groups, for instance with sed:
echo "2024-06-13   7 files changed, 400 insertions(+), 406 deletions(-) " |
    sed -r 's/^([0-9]{4}-[0-9]{2}-[0-9]{2})\s{3}[0-9]+\sfile(s)?\schanged,\s(([0-9]+)\sinsertion(s)?\(\+\))?(,\s)?(([0-9]+)\sdeletion(s)?\(\-\))?\s$/\1 \4 \8/gm'
That produces the correct output:
2024-06-13 400 406
But if the input string doesn't have insertions or deletions, sed just prints nothing for that captured group. Eg.:
2024-06-13 400
And I have no way to tell if the single number are insertions or deletions. **Is there anyway to extract the groups from each line, but print a "0" as placeholder if the group doesn't exist?** (not necessarily with sed alone, and not necessarily in a single command).
Mister Smith (133 rep)
Aug 10, 2024, 10:26 PM • Last activity: Aug 12, 2024, 08:01 PM
0 votes
1 answers
579 views
cd into directory with git lfs files takes very long
I have a (data) repository with ~50GB of data, split into =60 seconds. 1. Why is that, given that I just `cd` into the repository? `git lfs filter-process` converts between pointers and actual data -> when I `cd` into the repository I should not trigger converting since I did not do a `git lfs pull`...
I have a (data) repository with ~50GB of data, split into =60 seconds. 1. Why is that, given that I just cd into the repository? git lfs filter-process converts between pointers and actual data -> when I cd into the repository I should not trigger converting since I did not do a git lfs pull or something? 2. Even if it needs to check some pointers and convert, what could cause this process to take >=60 seconds? The system's M2 NVMe SSD is fine (benchmarked reading/writing speed -> above 3GB/s).
daniel451 (1107 rep)
Nov 11, 2019, 07:22 AM • Last activity: May 23, 2023, 12:44 AM
0 votes
1 answers
4524 views
how to print out only commit author and commit date by using git log?
I want to list all commit by using git log, in which each line contain [commit author]: commit date For example: [name]: 7 February 2021
I want to list all commit by using git log, in which each line contain [commit author]: commit date For example:
user544283
Oct 8, 2022, 02:59 PM • Last activity: Apr 18, 2023, 07:18 AM
1 votes
1 answers
686 views
git show does not understand relative file names
I am using git to version control config files on my system. I have git root at the root of my filesystem `/`, and I control `/etc` and `/root`. When I am in `/root` and do: `git log .zshrc`, it shows me commit history. I want to display the contents of `.zshrc` for particular commit: # git show a10...
I am using git to version control config files on my system. I have git root at the root of my filesystem /, and I control /etc and /root. When I am in /root and do: git log .zshrc, it shows me commit history. I want to display the contents of .zshrc for particular commit: # git show a100e3515779a900509b52230d449a6446fa110b:.zshrc fatal: Path 'root/.zshrc' exists, but not '.zshrc'. Did you mean 'a100e3515779a900509b52230d449a6446fa110b:root/.zshrc' aka 'a100e3515779a900509b52230d449a6446fa110b:./.zshrc'? # git show a100e3515779a900509b52230d449a6446fa110b:/root/.zshrc fatal: Path '/root/.zshrc' exists on disk, but not in # git show a100e3515779a900509b52230d449a6446fa110b:root/.zshrc # git show a100e3515779a900509b52230d449a6446fa110b:./.zshrc only the last 2 commands works. Why do .zshrc and /root/.zshrc not work, and why do I have to use the least convenient notation such as ./.zshrc ? Is there some configuration option that I can change, so that git understands .zshrc and /root/.zshrc ?
Martin Vegter (586 rep)
Jul 28, 2022, 06:55 AM • Last activity: Aug 5, 2022, 07:48 AM
1 votes
1 answers
5035 views
Format datetime as UTC with strftime (for use in git)
I can format dates and time pretty flexibly with `strftime`, but from what I can see, this only will give times in my local timezone; I can add the timezone offset (e.g. `'%Y %m %d-%H:%M:%S%z'` for a particular time yields `2022 02 14 16:21:35-0800`), but what I actually want is the datetime for UTC...
I can format dates and time pretty flexibly with strftime, but from what I can see, this only will give times in my local timezone; I can add the timezone offset (e.g. '%Y %m %d-%H:%M:%S%z' for a particular time yields 2022 02 14 16:21:35-0800), but what I actually want is the datetime for UTC. (For that example, 2022 02 15 00:21:35.) Is this possible with strftime? (Context: I'm fiddling with git log --date=format trying to get a format which matches go.mod fake versions. The --date=format:'%foo%bar' option, for defining custom formats, delegates to system strftime. I'm on Mac OSX Monterey and using bash. EDIT: Solution was somewhat more complex due to being used in git; changed the question description to reflect that.)
jkmartin (113 rep)
Mar 3, 2022, 08:03 PM • Last activity: Mar 22, 2022, 08:37 PM
2 votes
3 answers
597 views
Echoing from a variable in a specific part of a string
I am trying to make a command for having a nice-looking `git log`. Say I have the following: ``` git log --color --pretty=format:"%C(cyan) " --abbrev-commit ``` What I would like to do is to make a variable that takes `%an` and decides what colour it will be based on the output string. So far, I hav...
I am trying to make a command for having a nice-looking git log. Say I have the following:
git log --color --pretty=format:"%C(cyan)" --abbrev-commit
What I would like to do is to make a variable that takes %an and decides what colour it will be based on the output string. So far, I have
USER=$(if [ ! %an = "my own user name" ]
    then
        echo "%C(cyan)"
    else
        echo %C(bold blue)
    fi)
So then I put the variable into the git log such that I have
git log --color --pretty=format:"$USER" --abbrev-commit
Which should make is so that if a commit has been done by *me*, it will print my username in cyan; else, it will print the collaborator's username in bold blue. However, it doesn't. I'm just wondering if someone knows what I'm doing wrong here? I suspect it is something to do with printing the variable into an environment that is already a string, but I don't know how to fix it. Any help is appreciated!
Jake Ireland (225 rep)
Sep 22, 2019, 01:45 AM • Last activity: Sep 22, 2019, 01:32 PM
2 votes
3 answers
2838 views
How to find which author and committer has done more commits to a project using git log?
I have been browsing [Git Basics - Viewing the Commit History][1] as well as [Git Tools - Searching][2] and while most of the ways seem straight-forward I have been trying to figure out if there was a way to figure out the author who has done the most commits or/and the committers who has done most...
I have been browsing Git Basics - Viewing the Commit History as well as Git Tools - Searching and while most of the ways seem straight-forward I have been trying to figure out if there was a way to figure out the author who has done the most commits or/and the committers who has done most of the commits in a porject. I am sure there would be some ways like - 1. Find the author who has done the most commits in a project. 1. find the authors who have done the most commits in a descending manner. 1. Find committers who have done the most commits in a project and things like that. It could make for some interesting analysis of a project's state per se. Do people have any idea what could be done in the above instance? I am on Debian buster.
shirish (12954 rep)
Apr 9, 2018, 09:08 PM • Last activity: Sep 2, 2018, 06:29 PM
1 votes
1 answers
73 views
Getting differences of file between specific revisions/branches
I have 2 different branches A,B that have a (slightly different) version of a file X. I am interested in getting the commits that added some specific patterns in branch B. What I do roughly: `diff files| grep "^\+" | grep "$PATTERN" | for loop grep -n.. do git blame -L done` This works but I was won...
I have 2 different branches A,B that have a (slightly different) version of a file X. I am interested in getting the commits that added some specific patterns in branch B. What I do roughly: diff files| grep "^\+" | grep "$PATTERN" | for loop grep -n.. do git blame -L done This works but I was wondering if I am re-inventing/going a roundabout for something that is readily supported in git. Is there a better way?
Jim (1479 rep)
Jun 7, 2018, 10:03 PM • Last activity: Jun 7, 2018, 10:48 PM
Showing page 1 of 9 total questions