git branch commit does not merge into master - xcode

From git window, I executed these commands:
git branch
master
*wcopy
git commit -am "modified provider features"
On branch wcopy
Your branch is up to date with 'origin/wcopy'.
nothing to commit, working tree clean
git merge wcopy
Already upto date
git push origin master
Everything up-to-date
I go to git hub repository
Branch master says:
latest commit 9 days ago
Branch wcopy says:
This branch is 2 commits ahead, 5 commits behind master.
Latest commit db8bdca 18 minutes ago
I checked brnach wcopy the code is upto date
But master is behind.
I merged into master via git command, but it still shows two separate branches with master behind wcopy
(1) How can I bring master upto date?
(2) Also I renamed a file DB/Model.xcdatamodeld to Model.xcdatamodeld on my source.
But the wcopy branch shows the path as
DB/Model.xcdatamodeld/GridModel.xcdatamodel
says this path skips through empty directories.
If I look at the actual code on the source, it shows the path correctly as DB/Model.xcdatamodeld
I don't know why the difference?

Instead of doing this:
git merge wcopy
By doing that you merged wcopy into itself (which is not what you require). You should have switched to the master branch, then did the merged wcopy branch into master by doing this:
git pull origin wcopy
# to make sure you are up to date on wcopy branch
git checkout master
# to have your master branch up to date with the remote.
git pull origin master
git merge wcopy
# resolve possible merge conflicts if any.
git push origin master
This should resolve all your problems and merge branch wcopy with master.

I merged into master via git command, but it still shows two separate branches with master behind wcopy
When you did this:
git merge wcopy
You merged wcopy into itself, the wcopy branch, which of course didn't do anything. You should have switched first to the master branch, then did the merge:
git checkout master
git merge wcopy
# resolve possible merge conflicts...
git push origin master

Related

GitHub - reset local branch and pull new changes

I cloned a repository and checked out specific branch and start editing one file.
My friend also cloned and checked out the same branch and start editing the same file.
We then troubleshoot together on his computer and confirm that everything is working.
He then pushed all changes to the same branch.
How do I properly reset/cancel all my changes (of the same branch) and just pull new ones?
(the ones that he pushed)
You can first discard all your changes
git reset --hard
Then you can pull his version of the branch that he pushed
git pull
How do I properly reset/cancel all my changes and just pull new ones?
(the ones that he pushed)
There are few options:
Delete the local branch and check it out again:
# delete your local changes
git branch -D <branch name>
# fetch the changes or checkout the branch
git fetch --all --prune
# now checkout out the desired branch again
git checkout <branch>
Reset to any given point
# "remove" all your changes from the tip of the branch
# see the next section on how to get the required SHA-1
git reset <SHA-1> --hard
# grab the changes from the remote
git pull origin <branch>
How to find the last common commit?
# Get latest changes from the remote
git fetch --all --prune
# find the last "shared" commit of your 2 branches
git merge-base <branch> origin/<branch>
Check if your branches are up to date
# show remotes and local branches and they status against the remote
git remote show origin

Files committed do not appear after git commit, git stash, and git stash pop

I'm very new to this git thing, and as far as my experience goes, I've never encountered something like this before.
I've multiple local branches that I frequently switch around with, since I work with a group, and use other branches as a reference.
In this case, one of my friends committed and pushed something to his branch, and he suggested we have a look-see.
So I committed my changes on my own branch, but as usual, there are those Xcode files that magically edit themselves whenever we just open them, so I thought it would be a good idea to just git stash them (after the commit) and deal with them later, just so I can checkout my friend's branch and fetch the update.
After that was done, I switched back to my branch, and did git stash pop, and checked-out said files that aren't really important.
Then I noticed the files I created are gone.
I tried to do a git revert but it did nothing, not that I understood what happened, anyway.
Here's the list of commands I put in:
git add Integra-Geochemistry/Controllers/WaterSamplingFormOneViewController.swift
git add Integra-Geochemistry/Views/WaterSamplingFormOneView.swift
git add Integra-Geochemistry/Xibs/WaterSamplingFormOne.xib
git status
git commit -m "Initial commit - added WaterSamplingForm"
git status
git branch
git branch dev/surface-thermal-sampling
git checout dev/surface-thermal-sampling
git checkout dev/surface-thermal-sampling
git stash
git status
git checkout dev/surface-thermal-sampling
git pull origin dev/surface-thermal-sampling
git branch
git status
git branch
git checkout dev/watersampling
git status
git stash pop
git checkout Integra-Geochemistry/Xibs/AddRadonFormView.xib
git checkout Integra-Geochemistry/Xibs/RadonReadingFormFourView.xib
git checkout Integra-Geochemistry/Xibs/RadonReadingFormThreeView.xib
git checkout Integra-Geochemistry/Xibs/RadonReadingFormTwoView.xib
git checkout Integra-Geochemistry/Xibs/RadonReadingFormView.xib
git log
git revert 63947089d3479fff91ae4fb2ba5d59bd39d0c30d
For reference, here's the log file (after I did the git revert)
commit 8f5a3b8a4db5bad0a750ba08cd2d5b6a8a2fe18e
Author: <-------->
Date: Tue Jan 5 17:28:19 2016 +0800
Revert "Initial commit - added WaterSamplingForm"
This reverts commit 63947089d3479fff91ae4fb2ba5d59bd39d0c30d.
commit 63947089d3479fff91ae4fb2ba5d59bd39d0c30d
Author: <-------->
Date: Tue Jan 5 17:13:35 2016 +0800
Initial commit - added WaterSamplingForm
I've done a lot of committing, pushing and switching branches, but I never had anything disappear on me like this.
Is there any chance my files are okay and recoverable? I'd hate to start over. Thanks.
Is there any chance my files are okay and recoverable? I'd hate to start over. Thanks.
Yep.
type git reflog and checkout the desired commit that you want to get back to.
Basically every action you perform inside of Git where data is stored, you can find it inside of the reflog.
Git tries really hard not to lose your data, so if for some reason you think it has, chances are you can dig it out using git reflog.
What this means is that you can use it as a safety net: you shouldn’t be worried that a merge, rebase, or some other action will destroy your work since you can find it again using this command.
Read more about it here

How can I get changes from master into feature branch

Using windows 7 and git version 2.5.3 and I am trying to update my featurebranch with the latest from the master:
git checkout myfeaturebranch
git pull origin master
There are no errors but when I go:
git checkout master
then one of the files is different to the same file in the featurebranch. What could have caused this? Did I stuff up the tracking settings or what could it be? I would expect it to be the same?
What you did is just simply pull the remote tracking from master. Then when you checkout master again, there is no different.
If you meant to merge current master to your feature branch. You can do this:
git checkout master
git pull origin master
git checkout featurebranch
git merge master
I needed to add tracking: git branch --set-upstream-to=origin/master master

How to merge from upstream branch?

Here is my git setup (we use Git + Atlassian Stash in our corporate network):
upstream:
master
origin (my fork of 'upstream'):
master
branch1 (branch of master, with a few commits on top of it)
clone (local; clone of 'origin'):
master
branch1 (ahead of 'origin:branch1' by 1 commit)
What I want to do:
I want to merge upstream:master -> clone:branch1. I know there will be conflicts with this merge (since I changed files in my branch1 that others have changed in upstream). Once this is done I hope to push my changes back to origin:branch1, which will include my 1 commit + latest base from upstream (I want to keep up to date with the master branch, since that's the one I branched from). Along with this I want it to be a rebase, so that the commit history is clean and doesn't spider-web all over the place.
Another note is that I do not use git command line directly. On Windows, I'm using SmartGit, so if anyone knows instructions for that tool that would be most ideal.
How can I properly merge like I have described above?
If no one else has cloned or is working with branch1, you can rebase it on top of master, once you have updated master to upstream/master.
First, fetch upstream (SmartGit: Remote/Pull, select "Fetch Only")
Then reset master to upstream/master (SmartGit: Local/Reset)
Now rebase branch1 on top of master (SmartGit: In the Branches view, you can right-click on a branch like master and select Rebase HEAD to rebase your current HEAD onto the selected branch master)
Resolve merge conflicts if necessary.
Finally push (force the push) of branch1 to origin (SmartGit: In the context menu of the Branches view, you can invoke Push and Push To on local branches).

Git Status does not show 'ahead of' after edit and commit to local repo

Our company's workflow is to clone master branch into a _Test branch as we work on new features and we continually push/share this _Test branch until a set of features are complete and approved by client, then we merge to master branch and build and publish our sites. Then rinse and repeat.
The problem I'm having is git status isn't showing the correct ahead/behind (or more likely, I may not understand what it is supposed to show) while working on the _Test branch. If I do the following steps:
git checkout _Test
git pull --rebase origin _Test # get latest code
edit some files
get commit -am "Test commit"
git status
After step four, the git output is
[_Test d6fa824] Test commit
1 file changed, 1 insertion(+), 1 deletion(-)
Then after step five, the git output is
# On branch _Test
nothing to commit, working directory clean
Shouldn't it say?
Your branch is ahead of 'origin/_Test' by 1 commit.
If I look at qgit or gitk they show origin/_Test and remotes/origin/_Test respectively (correctly) 1 commit behind the last test commit. I'm running msysgit and git version outputs:
git version 1.8.1.mysysgit.1
So I'm confused why the output from git commit doesn't state that I'm ahead of origin/_Test (when obviously I am since I just committed) and why git status doesn't state same information.
Let me know if I need to provide any more info.
I resolved this problem.
You basically need to set up git tracking using
git branch --set-upstream *branch_name*
Read my full explanation here

Resources