Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git ignore accidentally commited file

Tags:

git

I'm working on a project with 4 member of team, everyone have different files config, and we're already using git update-index --assume-unchanged to/the/file but the newcomer hasn't noticed to use update-index to the config files and accidentally pushed the file to the repo as in:

application/config/database.php

And we're working with branches, while we're pulling the file on master it got no warning/something. But the database config file has been changed, and everytime we tried to change branches, this following files always needed to checked out before we change branch.

Is it any method we could ignore this file as if anyone has been changed it? So it wouldn't prompt us to checking it out before we change branch.

Thank you in advance.

like image 913
sun station Avatar asked Sep 07 '16 04:09

sun station


People also ask

Does Gitignore remove files already committed?

Let's say you have already added/committed some files to your Git repository and you then add them to your . gitignore file; these files will still be present in your repository index.

How do I ignore a commit file?

Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.

How do I ignore changes in git?

In the Git Changes window, right-click any changed file that you want Git to ignore and choose Ignore this local item or Ignore this extension.


1 Answers

  1. Remove the file from git : git rm --cached file
  2. Commit and push the change
  3. Add path file in .gitignore file on root folder of your repo. This will protect you fron new user to commit the file
  4. Commit and push the .gitignorefile

Documentation : gitignore

like image 140
Flows Avatar answered Oct 31 '22 13:10

Flows