вторник, 6 мая 2014 г.

Git assume unchanged files

Working on the BBB mobile client I came to the problem that when I want to test the client with my local server I need to change the server address in the LoginPageViewMediator file.

Once I am done with local changes and testing and want to proceed with pushing the code to github, obviously Git will tell me that LoginPageViewMediator was changed and will give an option to either checkout the master version of it(reset) or add it to the commit. What I used to do - is every time before the submission I will discard the changes in LoginPageViewMediator with git checkout command, push my branch, and then when I start working on another branch I have to do the same procedure with changing server address again.

Luckily, Git has a command to assume that specific file is unchanged, however the file will contain all your changes.

Now I can do it only once: 

git update-index --assume-unchanged LoginPageViewMediator.as 

and then file is not marked as changed anymore.

If I actually decide that file needs to be changed and included to my commit - I can revert file to the default state:

git update-index --no-assume-unchanged LoginPageViewMediator.as 
 
Now, file is marked as modified and ready to be added to the submission.
 
Also, if you want to see all the files that were marked with --assume-unchanged.
Following command worked for me:
 
git ls-files -v | grep ^[a-z]

Hope this helps.