Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict git from tracking / updating local changes?

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
like image 380
Max Wolfen Avatar asked Apr 21 '18 10:04

Max Wolfen


1 Answers

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

like image 162
CodeWizard Avatar answered Oct 22 '22 07:10

CodeWizard