Reputation: 2894
I work in C# with Unity, and it often touches a lot of files that don't want to commit. My changes that I want to commit are almost always exclusively .cs files. I created a git alias to stage all of my .cs file changes while ignoring everything else. That alias worked, but I realized that after doing the add
that I always end up double-checking the results by doing a git status
, so I decided to combine the two into a single alias.
addcs = !git add ./\\*.cs && git status
This alias works, however, the git status
always shows the results as if I was calling it from the parent branch.
So just doing a git status
might show up like this:
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: Scripts/Foo.cs
Calling my alias, which calls a git status
within it, shows up like this:
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: ParentDirectory/Scripts/Foo.cs
I tried an alternate alias, thinking that maybe the ./
within my alias might be somehow affecting the git status
, but this alias doesn't behave any differently:
addcs = !git add '**/*.cs' && git status
I'm curious if anyone knows why the git status
might be behaving this way, and if there's something I can change with my alias to avoid it.
Upvotes: 0
Views: 62
Reputation: 6890
You could add an unconditional refresh of the index between the addition and the status check with git update-index --really-refresh
.
Like --refresh, but checks stat information unconditionally, without regard to the "assume unchanged" setting.
Your alias could be rewritten as follows:
git config --local alias.my-add '!sh -c "git add *.cs && git update-index --really-refresh && git status"'
Upvotes: 0