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.
Related
So I am very new to Github. Please forgive me if i am asking a stupid question. So first did some reading on Github and tried to understand the philosophy about it. So i am working on my first ruby on rails app (very excited) I generated my new app and made my first commit by pushing the empty app to Github. So now i have a master branch.
Then i created a couple of models and added some fields to the tables i made. Now i would like to push this change on Github . What do i do and how? I KNOW some of you will say why would you push a change so small but i am just trying to learn GIT so then when i work on huge projects i am ready.
I basically want to commit the changes to the masters . How do i do this? I USUALLY see other peoples gits and they have messages like "fixed feature 1" 1 hour ago etc. So i want to do the same.
Please advice.
You would do that just like you pushed your earlier code - by pushing the commits you have made to remote repository.
If you are on the master branch, this will do: git push origin master (replace origin with your remote name - git remote -v will tell you all your remote names).
If you are on a feature branch, you can checkout to the master branch and then merge your feature branch - git checkout master and then git merge <feature branch>, and then push your changes again using git push origin master.
EDIT:
You can add a shortname using git remote add origin <link to remote repository>, and then use origin to push.
I am new to git as well and the answer above sounds better then mine. I have bash script on github (https://github.com/caroldomokos/columbo) which is work in progress for some time. I have the master locally as you do. When I make a change on the script I first do "git commit -a" and then "git push". I am in the "columbo" forlder on my pc. If you add a new file you first have to tell git to add it: "git add ". You can always use "git status" to see what is tracked and what has changed.To examplify I created this small sequence for you :-)
hpbcadom#LUBUNTU32:~/columbo$ echo "Git example" > example_file
hpbcadom#LUBUNTU32:~/columbo$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add ..." to include in what will be committed)
example_file
nothing added to commit but untracked files present (use "git add" to track)
hpbcadom#LUBUNTU32:~/columbo$ git commit -a
[master d799b3a] to help I hope
1 file changed, 1 insertion(+)
create mode 100644 example_file
hpbcadom#LUBUNTU32:~/columbo$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.
In Git 2.0, Git will default to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Username for 'xxxs://github.com': caroldomokos
Password for 'xxxs://caroldomokos#github.com':
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 288 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To xxxs://github.com/caroldomokos/columbo
dadf5af..d799b3a master -> master
I hope it helps :-)
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}
I'm using Git with a rails project.
Today i make a lot of changes and i forget to move to another branch, so all these changes are in the master branch but not committed yet.
this is what i get when i do git status command :
# 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/controllers/sessions_controller.rb
# modified: app/controllers/users_controller.rb
# modified: app/helpers/sessions_helper.rb
# modified: app/models/user.rb
# .....
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# app/assets/javascripts/password_resets.js.coffee
# app/assets/stylesheets/password_resets.css.scss
# app/controllers/password_resets_controller.rb
# .....
# ......
no changes added to commit (use "git add" and/or "git commit -a")
how i can solve this error and move all these untracked files from master to another branch already exists ? thank you.
Just create a new branch and then commit, e.g.:
git checkout -b my_branch
git commit -am "My commit."
If there are no commits marked C1, C2, etc. below
You're in the simple case; just use Henrik N's answer.
If there is a tracking branch
Your updated question/comments suggests that you have both committed changes and uncommitted changes, and you did them all on some tracking branch, such as master that tracks origin/master or devel that tracks origin/devel, but that you have not pushed any of them yet. (I'll assume master but you can just change each master to the feature/development/whatever branch name below.)
As a diagram, your repo's commit tree and working directory/index now looks something like this:
M1 -...- M5 -- M6 <-- origin/master
\
C1 -- C2 <-- master, HEAD=master
\
i, w <-- "index" and working-tree files
Here i is the stuff in the index (git add dir/file1, git rm file2, etc), which git status shows as changes to be committed, and w is the stuff in your working directory that git status shows as changes not staged for commit.
Here's what you want it to look like:
M1 -...- M5 -- M6 <-- master, origin/master
\
C1 -- C2 <-- my_branch, HEAD=my_branch
\
i, w <-- "index" and working-tree files
Remember that branch labels are like sticky-notes ("yellow stickies" or "Post-It® notes" or whatever): they have a name written on them and are pasted on to a commit. So what you have to do is add a new sticky-note, my_branch, pointing to commit C2, and also make HEAD refer to the new branch name:
git checkout -b my_branch
This uses the previous value of HEAD to name the commit that my_branch is pasted-on-to. Since that commit is C2 you now have both master and my_branch here. It then rewrites HEAD to point to the name my_branch. Now you have:
M1 -...- M5 -- M6 <-- origin/master
\
C1 -- C2 <-- master, my_branch, HEAD=my_branch
\
i, w <-- "index" and working-tree files
Now you need to move the sticky-note labeled master to point back where origin/master points. There are two ways to do this, with git reset, or with git branch. Using git reset is harder, so let's do it with git branch:
git branch -f master origin/master
The -f (force) flag tells git branch to change an existing sticky-note, rather than failing because it exists, and origin/master gives which commit master should point-to: so git peels the label off C2 and pastes it on M6, and you have the setup you wanted (the 2nd diagram).
Summary: it's just two commands:
git checkout -b my_branch # create new branch and change HEAD
git branch -f master origin/master # restore master to origin/master
You're now ready to check in changes as usual, on branch my_branch. (git add, git rm, git commit as needed.) That will add a new commit C3:
M1 -...- M5 -- M6 <-- master, origin/master
\
C1 -- C2 -- C3 <-- my_branch, HEAD=my_branch
What if there is no tracking branch?
Well, that's OK, it's just a little harder. Go back to the "have now" and "want" diagrams. In these diagrams, the commit I labeled M6 is the one you want master to name. You now have to find M6. Commits have these long hexadecimal-numeric (SHA-1) "true names" that never change, like 5e013711f5d6eb3f643ef562d49a131852aa4aa1 for example. (git rev-parse HEAD will show the "true name" for the current, i.e., HEAD, commit.) You can find that "true name", or you can find some alternate or abbreviated name that also names the same thing.
There are a whole lot of options for names, but let's stick with numbers that come out of git log and git log --oneline. The latter gives you something like this:
97206f5 peerish: set socket options earlier
4881af5 add semtest.c
b3f8bea fdm: repair example
where the number is an abbreviated SHA-1 and the text is the first line of the commit message. Since the logs are shown in reverse order, the top line is the most recent commit (C2 in the example above), and then each next line is the next one back (well, it's more complicated with merges, but close enough).
Let's say that from the above, you can immediately tell that the commit I labeled M6 is b3f8bea, i.e., that you need to skip two commits. Simply supply that value as the last argument to git branch:
git branch -f master b3f8bea
If your repo is huge and old, or has a lot of merge commits, you might want your logs to include more "decoration". I got these aliases from somewhere long ago:
[alias]
lol = git log --graph --decorate --oneline
lola = git log --graph --decorate --oneline --all
so that I can run git lol and git lola.
Alternatively, if you know for sure there were exactly two commits, master~2 (and in this case, after adding my_branch, my_branch~2) will get you the same SHA-1. The git rev-parse command shows you exactly which SHA-1 any given name "means". In one repo I have here, HEAD~2 is the same as origin/featureX:
$ git rev-parse HEAD~2
0f5a13497dd3da8aff8e452c8f56630f83253e79
$ git rev-parse origin/featureX
0f5a13497dd3da8aff8e452c8f56630f83253e79
but in general git log (or git lol, etc.) will get you the raw SHA-1 and you can add labels from there, as needed.
You simply need to create new branch.
Once you create a branch all the changes will be in the new branch.
and then clean your old stuff from master
// Checkout new branch
git checkout -b my_branch
// Prepare files for commit
git add .
// Commit changes
git commit -m "Your commit message"
// delete the dirty master
git branch -D master
// Now we are going to clean your changes from the master branch
// the -f is important in case you skipped the previous command to delete your master
git checkout -f master
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 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.