Tuomas Toivonen
Tuomas Toivonen

Reputation: 23522

How to freeze local changes in git

I have made some modifications to configuration files to run the project locally, and will never push these to the central repository.

Now, this makes the workflow annoying, as those changes are always present and restricts me to using handy shortcuts like git add . and git checkout . without commiting or reseting those changes, and the changes are easily lost by accidental command.

How do I make git to ignore these files locally from now on? First thing to come in my mind was to ignore them in .gitignore, but that just translates the problem to target .gitignore itself, and I'm concerned to accidentally messing up the repo.

How to freeze these local changes in a safe manner?

Upvotes: 1

Views: 431

Answers (3)

e.doroskevic
e.doroskevic

Reputation: 2167

Description

If you want git to ignore files, add them to your .gitignore.

If these files are already tracked, you might need to untrack them before git can ignore them. For that you can run

git rm --cached <filename>.<extension>

Example

git rm --cached development.log

For more information on how to go about your tracking issue. See this post.

Following instruction can be of assistance

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

git will not see the file as changed, and not try to commit (and thus push)

Upvotes: -1

Sanghita
Sanghita

Reputation: 1317

You can use use stash to make your changes hidden away while adding or committing files. when the new new updates are done you can apply the stash to your branch. Recommended Read

Upvotes: 0

AnoE
AnoE

Reputation: 8355

The way to handle this is to take the (real) configuration files out of the repository. You can keep template config files inside so people have some kind of examples.

Alternatively, if you really want to keep the config files inside (do they have passwords in them?) you can create a directory for your config files, have a separate file per environment, and symlink them on each host. Then of course, you do not add the symlink to git (add the symlink to .gitignore instead).

Keeping modified config files around is a constant hassle (think about git reset --hard...) and will not make you happy in the long term.

Upvotes: 3

Related Questions