3

I have recently switched from svn to git.
After failed thorough grind up with google and its crawelers, please find my situation as below:

Scenario

I have added files in .gitignore to makes git status silent about the untracked files.

Problem

Problem is that every time i rebase my branch, this file is also getting overwritten and i am seeing all untracked files on console.

Requirement

Is there any way to do git ignore <.gitignore_file> so that this file is excluded from getting rebased / overwritten on any operation??

hmijail
  • 1,069
  • 9
  • 17
NoobEditor
  • 15,563
  • 19
  • 81
  • 112

2 Answers2

3

You can define a custom merge driver which would apply just to .gitignore, and always keep the local version.
See in "Git: How to rebase many branches (with the same base commit) at once?" for a concrete example.

That merge driver "keepMine" can be associated with .gitignore, and be declared in a .gitattributes file present in each of your branches.
See "How do I tell git to always select my local version for conflicted merges on a specific file?".

echo .gitignore merge=keepMine > .gitattributes
git config merge.keepMine.name "always keep mine during merge"
git config merge.keepMine.driver "keepMine.sh %O %A %B"

With keepMine.sh put somewhere in your $PATH, not in the repository:

# I want to keep MY version when there is a conflict
# Nothing to do: %A (the second parameter) already contains my version
# Just indicate the merge has been successfully "resolved" with the exit status
exit 0

(For a KeepTheir.sh, see "How to stop a merge (yet again…)")

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
3

If you commit the .gitignore file, I don't see why you should have this problem. But nothing stops you to add .gitignore itself to .gitignore

As for an alternative way to exclude files, you can create a file .git/info/exclude which acts as a local .gitignore outside of the working directory.

Fabian Schmengler
  • 24,155
  • 9
  • 79
  • 111
  • i thought `.gitignore` is for local machine...why should i commit it?? – NoobEditor Jul 23 '15 at 07:24
  • Because it isn't for the local machine. You should use it only to ignore files that will be present in all instances (like binaries or other generated files). To ignore files specific to your local instance, there is `.git/info/exclude`, and for files specific to your local machine (like `.DS_Store` on Mac or `desktop.ini` on Windows), there is `~/.gitignore` – Fabian Schmengler Jul 23 '15 at 07:27