5

So, I learn git functions, but cannot make the file README.md executed from git branch update in the file .gitignore.

I had wrote the next in .gitignore but it does not help during push on server.

// .gitignore
# readme
README.md
LICENSE
2
  • 1
    You want to exclude Readme from GIT?
    – Melchia
    Apr 21, 2018 at 10:58
  • Yes, just from update, not delete @Melchia
    – Max Wolfen
    Apr 21, 2018 at 11:00

1 Answer 1

9

There is some crucial information you are missing. git tracks files as soon as you add them to the staging area. And once they are committed they will be tracked even when added to .gitignore and since your README is already added to git so git will track changes made to this file.

So adding it to your .gitignore as you already did will not work since it will be tracked by git from now on.

How to tell git to ignore local changes?

You can use the assume-unchanged

assume-unchanged

// Mark local fule so git will not detect local changes
git update-index --assume-unchanged <file>

// To get a list of dir's/files that are marked as assume-unchanged
git ls-files -v|grep '^h'

// To un-mark files
git update-index --no-assume-unchanged <file>

Adding assume-unchanged aliases

git config --global alias.hide "update-index --assume-unchanged"
git config --global alias.show "update-index --no-assume-unchanged"
git config --global alias.list-unchanged "ls-files -v|grep '^h'"

Now your .gitconfig should have the following aliases:

[alias]
    hide = update-index --assume-unchanged
    unhide = update-index --no-assume-unchanged
    list-unchanged = ls-files -v|grep '^h'

Usage:

git hide myfile.ext
git unhide myfile.ext

If you are using SourceTree you add custom action: enter image description here


enter image description here enter image description here

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.