0

Let's say I have branches 1234 and 5678. I have .gitignore with the config/main.config.php which is supposed to store this config file locally and not push merge pull it and so on anywhere, simply ignore it like it is doesn't exists.

In branch 1234 I see this config/main.config.php but when I switch to the branch 5678, this file disappears!

When I switch back to 1234, this file appears again.

1234 is an old branch. 5678 is a new branch created from another branch (not 1234).

I don't understand why this happens if config/main.config.php is in the .gitignore and not under version control.

this way it works only on the remote server, on my local PC file not disappear when i switch between branches this file mentioned to be ignored in .gitignore on the both local and server.

Eugene
  • 1,680
  • 3
  • 14
  • 23
  • 1
    What do you mean by "disappear"? In your working tree? In the output of `git status` as untracked? In the files actually under version control of your branches? Is your `.gitignore` itself under version control? (If yes, in both branches?) So many questions ... – Martin Nyolt Sep 02 '16 at 09:08
  • @MartinNyolt After thinking a bit, I don't think that `.gitignore` necessarily has anything to do with the observations. If his file isn't present in the other branch, I think Git can remove it when switching. – Tim Biegeleisen Sep 02 '16 at 09:09
  • @MartinNyolt 1) by disappear i mean it is not present inside the dirrectory where it should be 2) this happen only when Im inside `5678` in other branches this file exists 3) `git status` says nothing to commit or update my branch is up to date 4) i dont know if this file is under version control in any branch, how to check ? 5) i dont know if my `.gitignore` is under version control, how to check (same way as for question 4) ?) – Eugene Sep 02 '16 at 09:23
  • @Eugene I think that `.gitignore` is not really the cause of what you are seeing. The config file has been deleted in `5678`, and this is why it disappears when switching to this branch. – Tim Biegeleisen Sep 02 '16 at 09:27
  • https://www.google.com/search?q=git+how+check+if+under+version+control – Martin Nyolt Sep 02 '16 at 09:32
  • @TimBiegeleisen BUT on my local PC this doesnt happen, this only appears on the server... the road map of the branch was **local PC -> bitbucket -> server**. branch was created on my local PC, then pushed to bitBucket, then was pulled to the server. on my local PC everything is good and config file not disappear, but on the server this happens – Eugene Sep 02 '16 at 09:37
  • @Eugene For the purpose of this question, and in general, there is no sense of "local" and "on the server" in Git. Once you have synched up your local tracking branches, _everything_ is local, for all intents and purposes. AFAIK your observations are nothing more than Git removing a file from one branch which has been deleted (and Git ignored) in another branch. – Tim Biegeleisen Sep 02 '16 at 09:48
  • Maybe this helps: https://stackoverflow.com/a/55532030/2311074 – Adam Apr 05 '19 at 11:02

1 Answers1

1

I think this is the series of steps which led to your current observations:

In branch 5678 someone has deleted the file config/main.config.php, most likely because this is a config file and doesn't belong in the Git repository. This person then added config/main.config.php to .gitignore so that it would not get versioned again.

However, in the 1234 branch, the file config/main.config.php is still being versioned for some reason.

When you switch from 1234 to 5678 Git removes the config file locally because it is not longer being versioned.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • ok, according to your point of vision, how to: **1)** check inside branch `1234` that my file `config/main.config.php` is under version control or not **2)** under the branch `5678` be sure that this file "ignored or hidden" not really understand what that mean according to the git, because nothing happen to it when i work locally (file not disappear), this happen on the server only – Eugene Sep 02 '16 at 09:05