Pregunta

Consider the following scenario:

I have the following in my .gitignore:

files/dependency/config.lua

But since the file used to exist before adding it to gitignore, it was being tracked. I updated my index and removed the file manually following this question. Now, one of my colleague updated this file on remote server.

When I try to checkout to remote branch, it shows:

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

files/dependency/config.lua

Please, commit your changes or stash them before you can switch branches.

Aborting

So, I read about it; and most of the answers I found tell you to use git stash. Since I don't have any changes made on local repository, I can not stash them.

I used the --force option to checkout, but it also returns with an error:

git checkout --force -B myBranch remote/branchname
error: Entry 'files/dependency/config.lua' not uptodate. Cannot merge.

Here, I'd paste my terminal:

┌─[hjpotter92:HEDWIG]─[fooDir]─[06:46 PM] (master u=)
└──$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean
┌─[hjpotter92:HEDWIG]─[fooDir]─[06:39 PM] (master u=)
└──$ git checkout -b myBranch remote/branchname
error: Your local changes to the following files would be overwritten by checkout:
        files/dependency/config.lua
Please, commit your changes or stash them before you can switch branches.
Aborting
┌─[×]─[hjpotter92:HEDWIG]─[fooDir]─[06:39 PM] (master u=)
└──$ git stash
No local changes to save
┌─[hjpotter92:HEDWIG]─[fooDir]─[06:39 PM] (master u=)
└──$ git checkout -b myBranch remote/branchname
error: Your local changes to the following files would be overwritten by checkout:
        files/dependency/config.lua
Please, commit your changes or stash them before you can switch branches.
Aborting
┌─[×]─[hjpotter92:HEDWIG]─[fooDir]─[06:39 PM] (master u=)
└──$ git checkout --force -b myBranch remote/branchname
error: Entry 'files/dependency/config.lua' not uptodate. Cannot merge.

Question:

Is there some way to checkout the remote branch and then either force ignoring the file files/dependency/config.lua whenever someone pulls in my changes or something similar?

¿Fue útil?

Solución

I've currently made it work by indexing the ignored file once more. I used the command:

git update-index --no-assume-unchanged files/dependency/config.lua

and then the checkout command executed easily and properly. I'll leave this as an answer here. If someone can answer the following question, I'd be grateful:

Is there some way to checkout the remote branch and then either force ignoring the file files/dependency/config.lua whenever someone pulls in my changes or something similar?

Otros consejos

Responding to your earlier question:

Check git status if it shows that files/dependency/config.lua is modified.

Then you need to follow these steps:

  1. add file to gitignore. I think you already have this covered.
  2. git rm --cached files/dependency/config.lua
  3. commit this change.

Related: Remove an Existing File from a Git Repo

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top