Is there a way to prevent “git pop-ups” from marking files as modified?

I implemented git-hook to scan my commits via pyflakes and jshint, and after reading Yipit's comment on why most pre-commit interrupts are broken , I decided to implement its git stash and git stash pop suggestions.

Unfortunately, git stash pop marks the files as “modified”, which then causes my IDE to warn me whenever I return to this page, “modified on disk. Re-read from disk?” Then he asks: "Are you sure you want to edit this buffer?" and finally, "Are you sure you want to save this buffer over the modified file?"

I appreciate everything that he is trying to do for me, but he asks me about functionally non-existent “changes”.

Failed to play weird predictive games with touch , is there any way to prevent git stash pop from marking all the files that it affected as changed?

+3
source share
2 answers

I don’t think so (the timestamp has been changed as indicated in " GIT: adding local changes to an inactive branch ).

The easiest way is to configure your IDE to automatically update.

For example, for Eclipse, this will be the Update On Access setting.


Another approach would be to keep another local repo (one where there is no local modification, so there is no need to get stuck).
Your pre-commit hook remains in your current repo.

Your hook will use your current index (what you added), but a different repo. To do this, you need to commit using:

 git commit --work-tree=/path/to/other/local/repo -m "my commit message" 

If the hook does not work, you may have a hook after committing (still in your current repo), go to another repo and pull the current branch, updating its (untouched) working tree.

 cd /path/to/other/local/repo git --work-tree=/path/to/other/local/repo --git-dir=/path/to/other/local/repo/.git pull 

(Note that your hook, which lives in your first repo, must specify the work-tree and git-dir second repo to work correctly).
This is a simplified proposal, since it does not take into account the current industry you are working on (it involves only one "master" branch).
But you can detect the branch and adapt the hook from there (with the correct check and switch to the correct branch).

After the second update of your working tree (using the post-commit binding of the first repo), this second repo is ready to serve as an untouched working tree against which your pre-commit hook (your first and current repo) is running can work safely.

0
source

Are you sure the changes are non-existent? If the file is displayed with changes, something has changed, even if it is a space or resolution (executable state) of the file. You can use git diff to see the changes. You can also view the changes using the git commit -av (the -v flag will show the commit difference).

Your IDE will maintain the current “buffer” state of the file. If this file changes on disk (what git stash pop|apply will do), the IDE will recognize this and if you do not configure it to automatically update the file (usually in the settings / settings of the IDE), it may ask if you want to save the current buffer as a new file, which is usually not required when using git, or to reload the buffer with the changed state of the file.

0
source

All Articles