-1

In git, I ignored locally file using .git/info/exclude, based on answer to question. But now I can not pull from remote, this is the error that I am getting:

git pull 

error: Your local changes to the following files would be overwritten by 
merge: ignoredFile

Please commit your changes or stash them before you merge.

So I tried commit this file:

git commit -am "Message"


On branch master
Your branch is behind 'origin/master' by 4 commits, and can be fast- 
forwarded.
    (use "git pull" to update your local branch)

nothing to commit, working tree clean

So question is as in title, how to keep repository updated (git pull), while ignoring particular files locally.

EDIT: I ran commend:

git update-index --assume-unchanged ignoredFile 

Before git pull.

EDIT2:

git pull --rebase


error: Your local changes to the following files would be overwritten by merge:
    ignoredFile
Please commit your changes or stash them before you merge.
Aborting
Updating 0f37f00b..5ccc1b0a
First, rewinding head to replay your work on top of it...
error: Your local changes to the following files would be overwritten by checkout:
    ignoredFile
Please commit your changes or stash them before you switch branches.
Aborting could not detach HEAD
Bartek
  • 2,109
  • 6
  • 29
  • 40
  • 1
    Possible duplicate of [How do I configure git to ignore some files locally?](https://stackoverflow.com/questions/1753070/how-do-i-configure-git-to-ignore-some-files-locally) – teamyates Jul 11 '18 at 10:27
  • Why would you ignore the local changes? – axiac Jul 11 '18 at 10:35
  • I have some maven configuration that is more convenient to me, but I do not want to pollute team's repo. – Bartek Jul 11 '18 at 10:39
  • The configuration files should not stay in the source control. There should be a template or sample file in the repository and the name of the real file (manually created from the template/sample) added to `.gitignore`. – axiac Jul 11 '18 at 11:35

2 Answers2

0

Probably you are looking for:

$ git pull --rebase 

This will update your branch and move your changes ahead without creating a new branch, but not ignore your local files so that if required you could either push them or create a branch from it.

nbari
  • 25,603
  • 10
  • 76
  • 131
0

This would be quite hard, if not impossible (without some major hackery). In git, operations like mergeetc. (basically, almost all except git add) work on the whole tree by design; while there are some more or less arcane ways to change this, it is certainly not the most everyday thing.

If I may suggest another direction: you mention that you use this to fix some Maven settings which are local/specific for you. Instead of hacking around with git, find an official way to have local bits in your Maven configuration. Maven as build profiles for example, which should readily be able to fix your problem. It also supports (de)referencing environment variables, which might give you some more options.

AnoE
  • 8,048
  • 1
  • 21
  • 36