Git in Xcode 6.3: Master branch showing new files from other branches in red and won't compile - swift

I am using Xcode's integrated Source Control with Git and I have the following problem:
I have a perfectly working master branch and I want to work on two new features. So I create two new branches, where I add one new file at each branch.
Now when I switch back to the master branch or the other branch, after committing the changes and without merging (I don't want to merge yet), the files from ALL the branches appear in the project navigator (the ones that don't belong to the current branch are in red colour) and prevent my code from compiling as the compiler complains that these files don't exist.
My master at least should compile regardless of what I've done in other branches right?
Am I missing something trivial here?

Untracked files and unstaged changes do not belong to any branch. They only live in your working tree. When you switch branches, those files/changes are left untouched. If you want them to exist only in a certain branch, you have to add and commit all of them.
This should help understanding:
$ git status
On branch master
nothing to commit, working directory clean
$ >>file echo 'added line'
$ touch new_file
$ git status
On branch master
Changes not staged for commit:
modified: file
Untracked files:
new_file
$ git checkout -b new_branch
M file
Switch to a new branch 'new_branch'
$ git status
On branch new_branch
Changes not staged for commit:
modified: file
Untracked files:
new_file
So, as you see, unstaged changes are carried over when switching branches (this is by design). When checking out another branch, Git tells you which files contain changes (the line starting with Modified). This also holds for untracked files (Git cannot delete them, since you might need them), but their names are not explicitely output when checking out a branch.
To have Git delete files when switching a branch, you have to add (and commit!) them to a branch first.

Related

Git why newly checked remote branch has changed files?

I am new to Git. I have checked new remote branch at my local. As I am checking out a new fresh branch from remote, I don't expect any local changes in the files of my repository.
But somehow few files show changes. I am using Git on Eclipse IDE.
Why is so? Have I misunderstood the concept of new fresh branch checkout?
Update
Based on comments by Tim Biegeleisen and Sajib Khan my understanding was wrong as it is expected behaviour when you check-out remote as a local branch any previous uncommitted changes in the working directory ( Repository ) will carry to the newly checked-out local branch.
Just to put in simple words let me explain with example
Think that your working in master branch and add some new file (Eg file1.txt and file2.txt). Now you don't stage or commit these 2 files then it will be shown as untracked files.
Master Branch
Untracked files
file1.txt
file2.txt
At this particular point of time you switch to another branch then the files which were untracked will be shown in the newly checkout branch.
To over come this problem you can go for the following 2 ways
Stash the files from master branch and then switch to another branch, now it wont show the untracked files of master in newly switched branches. Stashing is nothing but saving the files and then reusing those at later point of time.
commit amending

Files appearing in "unstaged files", but can't stage (red blocking icon)

I have files that have no changes, but appear to be stuck in the staging area.
I started a bitbucket repo from an existing project and from the command line did a $ git remote add origin https://myusername#bitbucket.org/username/myrepo.git in my local project folder. Then did and initial commit from the command line as well $ git push -u origin master. I then loaded the project into the eclipse IDE using the IDE command File>Import Project From File System. After doing this, I found that some of the files from my project where in the staging area, but did not have any changes done to them and clicking them in gitkraken also reported that they were unchanged (yet I could not find a way to remove them from the unstaged files area). Trying to stage these files makes the clicking hand icon flash as a red blocking symbol and nothing else happens.
I tried staging and pushing these "ghost changes" manually in the cli, and get this output:
➜ myproject git:(master) git status
On branch master
Your branch is up-to-date with 'origin/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: .classpath
modified: .project
modified: some-query.sql
no changes added to commit (use "git add" and/or "git commit -a")
➜ myproject git:(master) git add .classpath .project some-query.sql
➜ myproject git:(master) git commit .classpath .project some-query.sql
...
<some git commit text>
...
➜ myproject git:(master) git push -u origin master
Password for 'https://myusername#bitbucket.org':
....
<some git push success text>
....
However, these files still appear in the "unstaged files" area.
If anyone has any idea what is going on here, input would be appreciated. Thanks :)
I believe you just need to commit the files.
git commit -m "adding .classpath, .project, and some-query.sql modifications"
Look up info on the difference between the working directory, the index, and the repo (there is a fourth area, called the stash, as well). When you stage you are just moving files and changes from the working directory into the index. To actually put those changes into your repo, you need to commit them, which will only commit the things in the index, not the changes just in the working directory.
So initially, the changes were just in your working directory. After git add <files>, they were staged in the index, but not committed. After git commit or git commit -m "<message>" then they are moved into a new commit in your local repo. It is only at this point that push will do anything, because push only moves commits (and references) from local to remote repos, it doesn't touch the working directory or index.

Can't pull latest source

I'm getting a very unhelpful message when I try to pull from git in team explorer:
I have nothing left to commit locally:
I could use some tips on where to start looking with this one, e.g. how to even find out what the two conflicts are (the error isn't clickable to drill or anything).
I have some untracked changes, but they are just package files such as the Entity Framework 6.1
Edit: git status:
On branch dev
Your branch and 'origin/dev' have diverged,
and have 2 and 16 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
When trying to git pull, it references files that are not showing up anywhere in vis studio team explorer to commit:
error: Your local changes to the following files would be overwritten by merge:
packages/Modernizr.2.6.2/Content/Scripts/modernizr-2.6.2.js
packages/Respond.1.2.0/content/Scripts/respond.js
packages/Respond.1.2.0/content/Scripts/respond.min.js
packages/bootstrap.3.0.0/content/Content/bootstrap.css
packages/bootstrap.3.0.0/content/Content/bootstrap.min.css
packages/bootstrap.3.0.0/content/Scripts/bootstrap.js
packages/bootstrap.3.0.0/content/Scripts/bootstrap.min.js
packages/jQuery.1.10.2/Content/Scripts/jquery-1.10.2.js
packages/jQuery.1.10.2/Content/Scripts/jquery-1.10.2.min.js
packages/jQuery.Validation.1.11.1/Content/Scripts/jquery.validate.js
packages/jQuery.Validation.1.11.1/Content/Scripts/jquery.validate.min.js
Please, commit your changes or stash them before you can merge.
error: The following untracked working tree files would be overwritten by merge:
Web/Web.config
packages/elmah.corelibrary.1.2.2/elmah.corelibrary.1.2.2.nupkg
packages/elmah.corelibrary.1.2.2/lib/Elmah.dll
Please move or remove them before you can merge.
Aborting
Stash by running git stash, then do a git pull

Subclipse tree conflicts

I'm trying to merge a trunk to a branch, but ending up with a lot of tree conflicts, leaving no files merged. To resolve the conflicts, I'm just opening the file and copying contents by hand which just defeats the purpose of a merge operation.
What is the right way to merge a trunk to a branch (in subclipse) ?
How was that branch created? Was it created by using svn cp, or were those files manually copied into that branch?
Let's look at the following:
$ svn mkdir trunk
$ vi trunk/foo trunk/bar
$ svn add trunk/foo trunk/bar
$ svn commit -m"Added foo and bar to trunk"
You now have two files on trunk.
$ svn mkdir --parents branches/1.0
$ cp trunk/* branches/1.0/
$ svn add branches/1.0/*
$ svn commit -m"Duplicated files onto branch"
What I have done is create two entirely different foo and bar on the 1.0 branch. These two files, according to Subversion have absolutely nothing to do with each other. If you make a change on the 1.0 branch, and attempt to merge these changes back to trunk, you will get a lot of conflicts with messages like "local add, incoming add".
What the above user should have done is this:
$ svn cp --parents trunk branches/1.0
$ svn commit -m"Branched trunk and not merely duplicate files"
Now, there's a relationship that Subversion understands between the files on trunk and on the 1.0 branch. Merging will go smoothly.
Here's another way to break a merge:
$ svn delete trunk/foo
$ svn commit -"deleted foo"
$ svn cat -rPREV trunk/foo#PREV > foo
$ svn add foo
$ svn commit -m"Added foo back in. Shouldn't have deleted it.
According to Subversion, there are now two completely different files named foo in the trunk. There's the file you deleted, and there's the file you added. These two files have nothing to do with each other. Imagine if I branched (the correct way using svn cp) to the 1.0 branch, then did my delete and copy of foo. The merge of the 1.0 branch back to trunk will have a conflict because the foo on the branch has no relationship with the foo on trunk.
To restore a file, you need to copy the revision that was deleted (or use svn merge -c).
$ svn cp -rPREV http://svn.repo/svn/trunk/foo#PREV .
$ svn commit -m"Actually old foo now has been restored! Merges will work"
If you branched incorrectly, or deleted and re-added files back to trunk, you will get conflicts. You can try using the --ignore-ancestory parameter, and you can use --dry-run to test your merge before running the actual merge.
If you manually merge, you can use svn merge --record-only to just record the fact you did a merge without actually doing one. This might help the next time you do a merge since you're at least recoding what you've manually done.

Merging pushed named branch with default causes error

I created a named branch using the mercurial eclipse plugin 20111225_Content_Build and after committing this branch locally, i pushed to my bitbucket repository without first merging with default. Now i have the default (inactive) and my named branch 20111225_Content_Build (active). I tried to merge these two following these steps:
hg update default
This gives me an error: abort: untracked file in working directory differs from file in requested revision: 'target/m2e-wtp/web-resources/META-INF/maven/org.bixin.dugsi/Dugsi_Manager/pom.xml'
and then when i try to merge: hg merge 20111225_Content_Build i get an error stating that i cannot merge with a working directory?
abort: merging with a working directory ancestor has no effect
I do have several generated target/ files that have not been committed or pushed, do i need to push these files in order to merge these two branches?
The message when you update is telling you your pom.xml files is not added in your branch, but is added in default. So when you hg update default Mercurial would need to discard the changes in your pom.xml file and overwrite it with the version that's checked-in in default, but Mercurial always refused to throw away data unless you really, really insist.
You've got two easy options:
If you want to keep the changes you made to pom.xml in the branch and merge them into the pom.xml stored in the default branch then you do this:
hg add target/m2e-wtp/web-resources/META-INF/maven/org.bixin.dugsi/Dugsi_Manager/pom.xml
hg commit target/m2e-wtp/web-resources/META-INF/maven/org.bixin.dugsi/Dugsi_Manager/pom.xml
If (instead) you want to discard the changes to pom.xml in the branch then just do this:
rm target/m2e-wtp/web-resources/META-INF/maven/org.bixin.dugsi/Dugsi_Manager/pom.xml
After either one of those you'll be able to do:
hg update default
hg merge 20111225_Content_Build