Edit local files without committing

Asked

Viewed 303 times

3

In a project there are some files that need editing to run the local server, such as .htaccess, config.php, among others.

In the branch master, We keep these files with the data in production. There are some collaborators who have different configurations to run a server locally, so they each work with different data in some files.

In this case, I would like to keep some files configured for my local machine without the need to do commit and not "mess up" the code of the branch master in an eventual merge.

The .gitignore delete these files in the repository. Is there any other solution? How is your working method to solve this problem?

  • You could put a pre-commit hook to remove files from an eventual commit. Reference (English): http://githooks.com/

2 answers

4


The standard/ideal is to tell git not to follow modifications of these files. This is done with Commando:

git update-index --assume-unchanged <filename>

The file will continue to be part of the repository, but local changes will not be considered during the commit.

When you want git to go back to following modifications, use the flag --no-assume-unchanged:

git update-index --no-assume-unchanged <filename>
  • This solution seems coherent, but I did not understand how to work with branchs already created. Can I use the command in the files in the master branch, for example, and from there the new branchs will already be with this effect? I noticed that in some branchs, even using this command, it asks to commit the files. They do not appear in "git status".

  • @Tiagoalves The command is not related to any particular branch. Changes to the file will be ignored during the commit, regardless of the branch. Another important note: this only affects the local configuration of git. That is, other developers will have to execute the same command if they want to.

1

The ideal would be to create a directory where you would put the required files running and delete it with the .gitignore.

For example, create a directory called build and when launching the run, move all files to this directory. Thus preserving the original file data, allowing editing and without creating the risk of them being added to the commit accidentally.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.