1

I have cloned repository and there is database.php file where credentials are different and every time I need commit and push, I have to add every file manually except database file, then push. Like:

git add file_name
git add another_file_name
.....
git push origin

Is there a way to ignore database.php file for all the commits I do, except when database.php is again modified for server.

justnajm
  • 4,422
  • 6
  • 36
  • 56

3 Answers3

4

From "Git - Difference Between 'assume-unchanged' and 'skip-worktree'", use git update-index:

git update-index --assume-unchanged -- database.php 

Any local change will be ignored by git status.
The next git pull will restore the remote content in the local repo.

To stop ignoring local change at any time:

git update-index --no-assume-unchanged -- database.php 
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Add database.php into .gitignore and clear it's cache by running git rm --cache .gitignore.

P.S : This file will always be ignore untill you remove it from .gitignore and clear the cache.

Shravan40
  • 8,922
  • 6
  • 28
  • 48
  • I want to ignore for temporarily – justnajm Jul 25 '16 at 08:23
  • 1
    start ignoring changes to a file: -------------------------------------------- git update-index --assume-unchanged path/to/file keep tracking again: -------------------------------------------- git update-index --no-assume-unchanged path/to/file – ansuman chauhan Jul 25 '16 at 08:35
0

Try This one:

Remove it from the project directory (without actually deleting it): git rm --cached database.php

If you don't already have a .gitignore, you can make one right inside of your project folder: project/.gitignore.

Put database.php in the .gitignore

Stage the file to commit: git add project/.gitignore

Commit: git commit -m "message".

Push your change to git.

ansuman chauhan
  • 427
  • 2
  • 9