Is it "ok" to commit to detached head after resolving conflicts when rebasing with TortoiseGit? - rebase

During a rebase, TortoiseGit gave me a list of conflicts to resolve. I did that and tried to commit, but then it complained that I was committing to a detached head. I was given the option to create another branch which I declined.
I've read somewhere that you don't normally want to commit to a detached head, but I read elsewhere that this is a normal part of the rebase operation. It appeared to work fine, and nothing seems to have been lost.
Did I do the right thing committing to a detached head in this case?

The rebase dialog has a commit button for this case - there is no need for a manual commit.
If you do a manual commit you create an additional commit in the history.

Related

libgit2: How to merge and commit after fetch?

I've managed to fetch from the remote, and I'm running the code below to get the changes staged in the local master branch.
git_annotated_commit * fetchhead_commit;
git_annotated_commit_lookup(&fetchhead_commit,
repo,
oid
);
git_merge(repo,&fetchhead_commit,1,NULL,NULL);
So now if I use the git command line tool to commit I get an automatic merge commit comment and after I can see that the log is the same as from the remote. I'm trying to obtain the same with libgit but my efforts so far in trying to create a commit of the merge results in the remote history to be lost.
How should I do a "proper" commit of the merged changes in order to preserve the history from the remote?
EDIT: Got a little further by doing a fast forward, but still if there are local commits these are lost after the incoming merge. Local changes are not lost, but staged after the merge and have to be committed again.
You can see my code here: https://github.com/fintechneo/libgit2/blob/master/jsbuild/jslib.c
The merge is happening in the fetchead_foreach_cb function which again is called from jsgitpull
And for the record this hack does work in the web-browser if anyone wonders what the emscripten stuff is about.
Create the merge commit with git_commit_create. The merge commit should have two parents. One is the current HEAD commit. The second is the same annotated commit you merged in git_merge (e.g. the fetch head).

Git hook that runs when you start the commit process in sourcetree?

Is there a git hook that runs when I hit the "Commit" button in SourceTree?
What I am trying to do is add everything. I've tried the following, in the file ./git/hooks/pre-commit:
#!/bin/sh
git add .
echo "hook added everything!"
It runs all right, but the timing is wrong -- it appears to run as a part of actually performing the commit. So what happens is that git first decides that that nothing has been added, so the commit needs to fail. THEN it runs the hook and adds everything. Lastly, the commit fails. If I repeat the commit, it will succeed the second time. But that's wrong on several levels. What I really want is to add everything before it opens up the window for the commit message. Then if I want to un-add some stuff, I should be able to do that in that window. Lastly, when I tell SourceTree to go ahead with the commit, I don't actually want a hook at that point, as I've already configured add/remove the way I want it to be.
The problem is, you cannot commit in SourceTree unless you have added something by staging it for commit.
You're trying to start the commit process in SourceTree before having staged anything - you simply cannot do that.

Git detached head state

I'm going through the tutorial for angularjs. In step 0 of the tutorial it instructs me to run:
git checkout -f step-0
When I ran this I got "You are in 'detached HEAD' state" which I take to mean that I just created a new feature branch called "step-0" that did not previously exist. Then I reloaded my web page and saw that all the cool stuff from the master branch is now gone. Instead I get this basic page that says "Nothing here yet!".
Now this is all correct behavior. My question is why did git checkout change the state of my code?
I could understand if the branch existed and I switched branches then yea that would change my code. But in this case it looks like the branch does not exist and I don't see a branch by the name "step-0" on github.
So in my mind I just branched off Master and created a new feature branch. Any changes in code don't make sense to me in this case.
What happened?
The "detached HEAD" message means that you're not at the tip of any branch. You've gone back to an earlier commit on the master branch, but you haven't created a new branch that begins there.
You got there by switching to the "step-0" tag. A tag in Git is basically an alias for a commit ID: "step-0" refers to the commit 96a9b5b7fa5e5667e099d25c20a4bb19992c0f72. Tags are commonly used for naming releases (e.g. a "v1.0" tag on the revision that was released as version 1.0), but in this case they're just used to make it easy to switch to specific revisions as you follow the tutorial. A branch isn't needed because you aren't going to be committing a divergent set of changes from there.
Branches and tags are similar in that they're both names that refer to commits. The difference is that a branch changes as you create new commits — the branch name is updated to refer to the new commit ID each time — whereas tags are typically used to record points in history that don't change, such as the contents of a specific released version. (It's possible to change a tag, but only in the same sense that it's possible to change the history of a branch: if you've already pushed the tag to others, you'll have to ask them to delete it and pull the new one instead. You can't force tag changes on others.)
If you want to start a new branch from the commit you've just moved to, you can do so: git checkout -b my-branch.

Unable to undo rebase stream

We were trying to rebase our stream.
After click on complete we got issue like some thing is corrupted. [Sorry my collegue did not take the screenshot of error]
we tried to redo the rebase operation.
It said unable to collect information about view
When we try undo rebase we got following error.
Rebase Stream
---------------------------
Error cancelling rebase of stream 'IELoc--Dev100'.
Integration activity change set is not empty.
---------------------------
OK
---------------------------
How to complete or undo the rebase now?
If you are in the process of cancelling, there is no going back: you must proceed all the way to completion of that "cancel" operation.
The technote "Rebase fails with error: integration activity change set is not empty" can give some elements to resolve the situation.
The problem can occur when other external operations have been done during the rebase: a cleartool rmver (delete version), for instance, would be very dangerous.
The idea of a cancel (of a deliver or a rebase) is to undo checkout all the versions previously checked out in order to be merged.
You need to make sure all those versions can be checked out: sometimes a right issue can prevent the unco, sometimes, the version was already checked in.
Now, if the activity associated with the rebase is actually empty, there is an utilty called 'ucmutil' which can reset the rebase state, making it "vanish".
But that should be used with caution, and under the supervision of IBM Rational Support.
See "Canceling UCM rebase fails with error: cleartool: Error: Rebase in progress on stream" and "About ucmutil".

Git, robots and diverging branches

I am trying to use git as something it wasn't made for - a database. Please feel free to tell me that this is a stupid idea.
Setup
One branch (let's call it robot) is being updated automatically by a script on a daily basis. The data comes from some other publicly available database.
Initially the master branch is the same as the robot branch.
Some of the data in the publicly available database is wrong, so I'll make a commit to the master branch and correct the error.
When the script detects any changes on the public database in the future, it will add those to the robot branch as a new commit (there's one commit per file).
Keeping track of differences
Now, I've obviously lost the ability to do a fast forward merge if I've modified the same file. But I could still cherry pick the good changes in the robot branch and import them into the master branch. The problem is that this might get rather messy after a while, when almost all the files have diverged.
How can I keep track of the difference between the different branches in a systematic way?
It sounds like you're looking for the git rebase command. This command allows you to update changes you've made to your master branch on top of the new head of the robot branch:
git checkout master
git rebase robot
There may be conflicts, if the database has been updated with a change to something you've changed in master. You must resolve those conflicts manually.

Resources