When I am switching between branches in git, I am seeing that files are changed even though no updates have been made. This has just started happening recently.
$ git status
# On branch dev
nothing to commit (working directory clean)
$ git checkout master
Switched to branch 'master'
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: App.Core/ViewModels/CriteriaViewModel.cs
# modified: App.Core/ViewModels/UserManagement/AccountTagsViewModel.cs
# modified: App.Core/ViewModels/UserManagement/TagViewModel.cs
#
no changes added to commit (use "git add" and/or "git commit -a")
These are files that I changed on the dev branch, but then added and committed. Any ideas as to what I'm doing that would cause this?
(Note that the new branch will have exactly the same files and history as the old one.) When you run git checkout xxx to switch branches, files from the new branch are extracted from the "object database", which is the archive kept under . git/objects/ that contains compressed originals of every file in every commit.
When you switch a branch, all files that are under control of Git will be replaced with the state of the new branch. That includes changes to files as well as additions and deletions. In your case this means that you have some files in your current 'local' branch that simply do not exist in the master.
To get the list of files modified (and committed!) in the current branch you can use the shortest console command using standard git: git diff --name-only master... If your local "master" branch is outdated (behind the remote), add a remote name (assuming it is "origin"): git diff --name-only origin/master...
Take away: changing branches does not touch/change/remove untracked or checked in files. Remember that the working directory and index are not 'cleared' before the branch content is loaded into it!
You can check if the difference is in the eol (end of line) characters in those "changed" files.
If it is, make sure your core.autocrlf is set to false:
git config core.autocrlf false
That would avoid any automatic conversion on checkout.
See "git replacing LF with CRLF" for more.
If you need to enforce a consistent eol, use .gitattributes
directives, as in "Fixing the line-endings in a Git repository using the .gitattributes
file".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With