I am new to XCode. Recently started working with a team on an iPhone project. We're using GitHub for our source control, and pulling/comitting/pushing straight from XCode (5.1).
We're all working on master at the moment.
I have noticed that our commit log has a ton of the following statements:
Merge remote-tracking branch 'origin/master'
These seem pretty superfluous. These items are almost always identical to a previous commit from another user.
Example Scenario:
User A and user B do a PULL to start working on code.
User A edits SomeViewController.m and does s COMMIT and a PUSH.
User B edits AnotherViewController.m and does a COMMIT and a PUSH.
User B is greeted with an error [from XCode] that he must PULL before he can COMMIT.
User B does a PULL, then a COMMIT.
Now there are 3 items in the commit log:
The change from User A
The change from User B
Merge remote-tracking branch 'origin/master'
But #1 and #3 are identical! What are we doing wrong? Or is this just a neccessary evil of using Git and XCode together?
One solution is to use the rebase command instead of a classic pull (fetch + merge).
You can check the option when doing a pull in XCode.
That would replay your local commits on top of the (fetched and updated) remote tracking branch.
In comamnd line, a nice option is:
fetch
try a merge
if not, try a rebase
See ""Merge remote-tracking branch..." What is this? I don't even. " and
"Why am I merging “remote-tracking branch 'origin/develop' into develop”?"
# download the latest commits
git remote update -p
# update the local branch
git merge --ff-only #{u}
# if the above fails with a complaint that the
# local branch has diverged:
git rebase -p #{u}
Related
I have created a private repository in bitbucket for a project on my own.
The other day I was showing it to some coworkers and I made a commit from another computer, which was saved remotely with another author.
Back at home, I made a pull and I got the error 'Nothing to fetch', nor can I upload changes because there are changes in remote that needed to be downloaded, so the branch has become unusable.
I'm working on eclipse in both cases.
Timeline:
Computer 1, user 1 (owner of repo)
Create project
Made serveral commits.
Computer 2
Checkout project
Made some changes.
Push to remote, (without realizing that the author was another, configured in eclipse for other unrelated projects).
Back to computer 1:
Pull: I get an alert message. Operation cancelled: Nothing to fetch.
Tried: Approve the commit, add that second author in the username alias list.
Also tried to unlock the situation by having the last commit go with the correct user. So now the branch history looks like this:
643480f Author User1 - Commiter User1
02d5072 Author User2 - Commiter User2
81e65a0 Author User1 - Commiter User1
7f6fe95 Author User1 - Commiter User1
071cbb7 Author User1 - Commiter User1
Ammend try steps:
git status
In the branch development Your branch is up to date with 'origin /
development'. There is nothing to commit, work directory clean
git checkout 02d507219b83053aa0de58f9f12b82a71de3e638
You are in 'detached HEAD' state. You can look around, make
experimental changes and commit them, and you can discard any commits
you make in this state without impacting any branches by performing
another checkout. If you want to create a new branch to retain commits
you create, you may do so (now or later) by using -b with the checkout
command again. Example: git checkout -b HEAD is now
02d5072... Changes in DB structure:
git commit --amend --author="User1 "
[HEAD detached a970307] Changes in DB structure: User1
"owner.user#gmail.com" Date: Wed Nov 6 08:39:32 2019 +0100 2 files
changed, 54 insertions(+), 2 deletions(-)
git push origin development
Everything up-to-date
You can amend the author name from other computer where the commit was initially pushed from using the below command.
git commit --amend --author="Your name"
Once updated, then you can push the changes to the remote repository.
If I execute git review git shows me "Working tree is dirty" error.
I made a commit and I sent to review. After that I update the branch from the upstream using git pull. Now I need to modify the previous commit message, so, there are my commands:
1) git reset <id-of-the-commit-to-modify>
2) git commit --amend
vim was opened to modify my commit. But here appears information about my commit and others commits as well and I don't know why. However, I modified the commit message and write/close vim.
3) git review
This command raise this error:
Errors running git rebase -i remotes/gerrit/master
doc/source/configuration.rst: needs update
doc/source/developing.rst: needs update
tools/sample_data.sh: needs update
Working tree is dirty
What I doing wrong?
git reset <id-of-the-commit-to-modify> without a mode option is defaulted to --mixed . This is what is said on the reset in the manual
--mixed
Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.
This basically means your index has been reset, but not your working files. So all files that you pulled from upstream are still left in your working tree.
You should use git reset --hard <id-of-the-commit-to-modify> This will reset your index and remove the files that came with your upstream pull. You can then amend your commit and send it for review.
once a change was pushed to Gerrit, then it can be fetched directly. On the Gerrit review board you can find the chekcout command for each patchset, something like this: git fetch ssh://ebalbar#gerrit.ericsson.se:29418/TCC/TitanSim refs/changes/86/129686/5 && git checkout FETCH_HEAD Then, you can amend the commit as usual, and push the new change again. AFter that checkout your local branch and reset it with the remote branch: git reset --hard origin/<remote_branch> also a nice answer how to modify a commit which was pushed directly.
I know there is a http deploy hook I can use but unfortunately it does not submit the branch name, here is what it does submit:
{"head"=>"7021419", "app"=>"appname", "git_log"=>"commit message", "action"=>"home", "url"=>"site url", "prev_head"=>"1d844b0", "controller"=>"account_sessions", "user"=>"heroku#user.com", "head_long"=>"7031429230228988d8f3312fa9e74d77b6c1bc14"}
I tried using the head or head_long to figure out the branch name with:
git branch --contains SHA
Which worked, but it is not 100% accurate as the same SHA could be in multiple branches. Same can be said about:
git reflog show --all | grep 7021419
I am pretty sure it is impossible to get the current branch name from within the deployed app as the branch deployed to Heroku is always the "master" branch. I was hoping I can send the deploy callback hook to another server and store the deployment record somewhere.
1. Detecting only
If it's just about heads, use
git rev-list --no-walk --glob=refs/heads
with a bit of --format and grep logic tacked on
2. Tracking locally
The simplest way would be using a tag.
Push the tag like a normal branch:
git push herokuremote tagname:publicbranchname
Unfortunately, that would just push the tag, not a branch... ; read on for alternative
(note I don't know/use heroku, so I don't know the naming conventions, sorry)
3. Symbolic branch reference
If you don't mind using a bit of plumbing, you can name a local ref as the one deployed. You can have a symbolic ref for the purpose:
git update-ref -m "deployed release candidate" --no-deref refs/heads/deployed master
If the same SHA is in multiple branches, they are effectively the same branch (at least at that point in time). If you're sure that SHA is the last commit of a branch, you can find it in .git/refs/heads/* where * is a list of files whose names correspond to branch names and contents are the SHAs.
It seems like you might be able to solve this recording problem by not using their API. Wrapping your deploy script (or Heroku's deploy binary, or a post-push hook) should give you the flexibility you need to notify a different service for record keeping.
I am working in ROR in a Ubuntu machine. I had done some changes in my files and commited it with a msg.
Now when i checked with the git log thing..
I am getting a new msg rite above my commited message as Merge Branch 'myname' .. Why is it so coming like this ?
Please give suggestions..
EDIT :
Date: Mon Oct 11 11:42:29 2010 +0530
Merge branch 'aruna'
You shouldn't worry about git "merge commits". The merge commit just contains the differences between your local version of the branch and the remote version of the branch. (hence why they appear when you pull and there were any changes).
Rebasing, exactly as suggested in pawien's answer is a good way to avoid those, but only if you know what you are doing. Rebasing should only ever be used in a local feature branch (a branch that you never push), because it re-writes all the commits that have been commited to the feature branch. rebasing a branch that has other peoples commits in it can accidentally delete commit history if you don't know what you're doing.
This is a git question and is not related to Rails.
So - it is quite normal in git and it will happen in situation like this
- aruna: X -> Y
/
master: A -> B -> C -> D .....
when you merge aruna with master (either by doing merge aruna on the master branch or just by pulling [pull is "two in one" command - it makes fetch & merge]) you will get new "merge" node that is the merge of both branches (nodes C, D & X, Y)
As you are asking I bet that you don't like it. So the possible solution is to rebase the aruna branch instead of merge. For example:
# normally commit everything in your aruna branch
git checkout aruna
git add ...
git commit -m "..." ...
git checkout master
git pull # it will just fetch as there is nothing to be merged
git checkout aruna
git rebase master # and solve possible conflicts
git checkout master
git merge aruna # it will *not* make the "merge node"
git push
EDIT:
As others mentioned - the rebasing is really no option if you already pushed the branch or you have other people who pulled your branch.
But still - rebasing is an option if you are merging your local private branch. Which is a quite common scenario. And as your branch is named "aruna" (your name) I thought that's the case. But as I think about it again there is no reason to think so :-)
While rebasing (local feature branch), you will lost some part of history that says that you did your commits in parallel. But the trade-off is that you will have simpler narrow tree.
I was using a github repository from a previous developer.
I am the only coder on this project, so I forked the project over to my own github repository.
Now I would like to commit soley to my repo.
Unfortunately, I realized that I never changed my .git/config , so I was still committing to the old repo. I just changed it to the appropriate url, and when I type :
$> git status
It returns :
=> Working directory clean.
But I know its not because I have several commits I've made. So my local box has different code then what it is pointed to on my repository.
My question is this. Obviously I'm halfway through the process of doing this. Do I need to re-fork to update, and then I'm good. Or is there a special command I need to run to let my local box know its 'git status' command is targeting a new repo to compare itself to? Equally, am I missing something else very important :D ?
Thank you everyone.
You can use git remote to manage your remote
rename origin
git remote rename origin old_origin
add a new origin
git remote add origin git://github.com/my/forked/repo.git
git fetch origin # will create all the remote branches references
# in your local repo
You can also easily setup a new upstream for your current master branch (git 1.7 and more):
git branch --set-upstream master origin/master
The "nothing to commit (working directory clean)" message of git status won't prevent you to push.
After changing the origin, you should see:
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by xxx commits.
#
nothing to commit (working directory clean)
That means you have some commits to push to your new origin.
Note: "git remote"(man) rename failed to rename a remote without fetch refspec, which has been corrected with Git 2.39 (Q4 2022).
See commit 5a97b38 (22 Sep 2022) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 20a5dd6, 10 Oct 2022)
remote: handle rename of remote without fetch refspec
Reported-by: John A. Leuenhagen
Signed-off-by: Jeff King
We return an error when trying to rename a remote that has no fetch refspec:
$ git config --unset-all remote.origin.fetch
$ git remote rename origin foo
fatal: could not unset 'remote.foo.fetch'
To make things even more confusing, we actually do complete the config modification, via git_config_rename_section().
After that we try to rewrite the fetch refspec (to say refs/remotes/foo instead of origin).
But our call to git_config_set_multivar() to remove the existing entries fails, since there aren't any, and it calls die().
We could fix this by using the "gently" form of the config call, and checking the error code.
But there is an even simpler fix: if we know that there are no refspecs to rewrite, then we can skip that part entirely.
git status only shows you the status of your working directory, not the entire repository. It seems like you only need to change the remotes that git push and git pull use by default. Open up .git/config and find your branch.<branch> entries and change them, as well as your remote.<remote> entries. For example, your master entry may look like this:
[branch "master"]
remote = origin
merge = refs/heads/master
Just change remote to reference your (forked) remote.
Also, your remote entry may look like the following:
[remote "myremote"]
url = git://github.com/me/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
You can add a push entry so that your master branch is pushed by default:
[remote "myremote"]
url = git://github.com/me/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
push = master
In whole, but I should include it in this answer. Is that before hand I manually altered my .git/config to include my new repository url. That's why I didn't have to rename or add any origin as Von suggested.
Then I just guessed this and performed
$> git fetch origin
Which returned
From git#github.com:gotoAndBliss/hq_channel
17326ca..043d395 master -> origin/master
* [new branch] panda_streaming -> origin/panda_streaming
+ 6ec9bf8...becbcc6 testing -> origin/testing (forced update)
Then on git status I got
# On branch testing
# Your branch is ahead of 'origin/testing' by 9 commits.
I git pushed origin testing, and I think I'm on target now.