What is the use of "git checkout -f" when "git status" shows tracked file changes on all branch

0

Issue

I have a tracked file (an old versioned file) that i modified on master branch.
The staus on master branch shows this file as modified but
The status on the topic branch also shows this file as modified.

Earlier there was an error “error: You have local changes to “X”; cannot switch branches” when i checkout to the other branch without doing a stash or without using “-f” in git-checkout.

i have checked “stackoverflow.com/questions/1304626/git-switch-branch-and-ignore-any-changes-without-committing” but that error doesnt occur and am able to checkout even when i have local changes.

Is there any kind of config that is causing this confusion?

Solution

It looks like the branch you’re switching to is in the same state as the branch you’re coming from. Each branch is a pointer on a tree of commits. Therefore, if two branches point to the same set of commits , you can switch between them without checking in local changes. The reason is that until you actually commit the changes, it does not make a difference to git which branch you commit them to. However, once you have commit the change, then one branch has it and the other one does not and their histories are now different.

Answered By – Carl

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More