简体   繁体   中英

Is there a way to keep git stash --keep-index from making Visual Studio think staged files have changed?

I've made a pre-commit hook to prevent commits that contain specific pieces of text using this method .

My problem is that if I change a .csproj file in Visual Studio (eg by adding a file to the project) and then stage my changes and commit them in Git then when I go back to VS to continue working I get prompted to reload the project because VS see the .csproj as changed even though it hasn't. This is a pain because now I have to click a button and wait for VS to reload the project every time I make a commit.

I've tracked the line in the pre-commit hook that causes this behavior down to git stash -q --keep-index .

Is there a way to keep this line from triggering this behavior in Visual Studio? Or an alternate approach to writing my commit hook that doesn't trigger this behavior? Unstaged files may contain the forbidden text and should not prevent the commit so I can't just remove this line.

I ended up switching to a completely different approach that doesn't require git stash.

Forbidden='STOP-COMMIT'
Found=$(git diff --cached -S"$Forbidden")
if [[ $Found ]]; then
    echo "COMMIT REJECTED Found \"$Forbidden\" references.
    echo "$Found"
    exit 1
fi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM