libgit2 equivalent of git reset? - libgit2

I'm trying to get used to libgit2 and so am making simple git app. I know git rm --cached <filepath> is removing the file from index (eg git_index_remove_bypath(idx, path)). Now am looking for git reset <filepath>
Does libgit2 have an example or some documentation on how to reset file to previous state aka unstage? The best explanation I found is this one but I really didn't get what he meant.
Any pointer or even example is appreciated

To unstage a file you want to write the current HEAD commit entry for the file into the index with git_index_add. See my answer to this question for some details.

Related

Working with GIt without branches

I am trying to work with GIT, without creating private branches.
What that means is I directly work on my cloned repository (master)
Now, Is that the right way to use GIT? I run into many issues related to updating my repository (GIT PULL / GIT FETCH). And most of the time, I am not able to use GIT Merge.
Is there a particular way in which i can use GIT MERGE, GIT PULL, and GIT FETCH. That will help me?
Looks like the best way to work with GIT is have branches.
Branch 1
GIT Commit
GIT PUSH
GIT MERGE master ( to fetch the newer changes)
Branch 2
GIT Commit
GIT PUSH
master
GIT Merge branch1
GIT Merge branch2
I dont think there any other way. Please correct me if i am wrong?
Jan Krueger's extended cheat sheet will help you cover the basics, and will expose you some common commands for using git.
IMO, git is a brilliant DVCS. If you have time; take a look at the structure of git and try to catch the ideas behind its design. For example this Tech Talk by Linus Torvalds.
Note: It looks like you are missing some core ideas behind using git, so please try to learn general approach of git before tackling with commands.
Note 2: As being a stalker, you seem to have general problems with git. So I repeat my advice once more. Learn basics, complete a tutorial, read/listen/watch a few useful source from notable people about git.
Also read about git stash. It saves your local uncommitted changes so you can pull cleanly. Then run git stash pop to replay those changes on top.

Storyboard got corrupted during a merge

In Xcode we pulled someone else's push and merged with local copy. However now the pulled copy has corrupted storyboard. The worst thing is we accidentally pushed those corrupted file to remote repo. Now is there any way I can solve this issue?
we are using SourceTree as our interface to Git.
One of our member has the last working copy as we haven't pulled any corrupted data from server to his copy.
Any potential solution for this situation? Thanks
Sorry but I'm not enough of a Git expert be be able to give you the exact commands, but there are git commands you can enter to revert a file to a specific revision/commit. If you hunt around the web you should be able to find them and revert the file.
You may have to use command line Git.
This may help Reset or revert a specific file to a specific revision using Git?
and this Rollback file to much earlier version using Git
A pull and merge is commited to the history like any other change so you just need to undo that commit. The git command to delete the last commit and restore your working tree to the previous commit is:
git reset --hard HEAD~1
(from Delete commits from a branch in Git)
This change could then be pushed back up to your server.

Getting current Git commit version from within Rails app?

How can I retrieve the current Git commit version from within a Ruby on Rails app?
Want to display the Git version (or maybe the last 6 letters or so) to serve as an App version.
Like #meagar said, use backticks to execute the shell command from within your app, but you may find these two commands more useful:
Full hash:
git rev-parse HEAD
First 7 characters of hash:
git rev-parse --short HEAD
You can invoke the git command from within your script:
commit = `git show --pretty=%H`
puts commit
Depending on your environment you may want to use the full path to the git binary, and possibly specify the GIT_DIR via an environment variable or --git-dir.
A more robust solution would be git show --pretty=%H -q. The -q flag quiets the output.
In order to remove the newline that is part of the output, you can use chomp. For example: system('git show --pretty=%H -q').chomp
The selected answer has the potential to actually return the diff when the commit is not a merge commit. Verified on git version 2.16.2.windows.1.
I presume that you want to include the app version in your HTML somewhere? The prerequisite is that you are deploying your repo with Capistrano in the default manner (you are uploading the repo, not sending up an archive file).
You can add some code to the Rails initializer as outlined here. That approach will get the SHA1 from the last commit, and make it available as an environment variable.
The other way to do it is have you Capistrano task generate a static file in the public directory with the commit SHA in it. You could include other info in this file that seems useful.

Do the entries in .gitignore get applied to the SVN repository when using git-svn?

If I tell git to ignore x amount of files and never add them to the repository, will those files also make it into the svn:ignore property? And if so, how can I keep .gitignore local to only my local git repository?
EDIT Sorry about the duplicate, I searched on here and couldn't find anything on it.
No, git will not do anything with svn:ignore.
From the documentation:
We ignore all SVN properties except svn:executable. Any unhandled properties are logged to $GIT_DIR/svn//unhandled.log
Also this other StackOverflow question is very similar.
If you want the .gitignore local to your repo, don't commit it.
Similar question:
How can you indicate files to ignore in svn when using git and the git-svn bridge
git-svn does neither .gitignore — svn:ignore, nor git attributes — svn properties conversion.
You may consider using SubGit instead. It does properly handle ignore, properties, merge-tracking data, etc. Among other things it works on a server-side, so one can use any Git client available to send changes to Subversion repository.
See documentation and comparison with git-svn.

'bzr update' wiped all my local commits. Help!

I think something bad might have happened to my changesets.
For the record, I have used git, hg and svn with general success before. My understanding of bzr is less complete.
Here's what I had (Windows XP):
1) A folder created using bzr's svn checkout. Call it stable
2) A folder branched from that which I was using for development. Call it development
My plan was to use commit --local on the development branch to keep track of changes, and it was working swell.
Then, I did a 'bzr update' on (because it complained when I tried to push). At the time, stable had a much older copy of the code. Well, now development has that same old copy. 'bzr log' shows no evidence whatsoever of my local commits!
Can someone explain to me what happened, and what I can do to recover my old code?
Ok, I found it. After some frantic searching, I uncovered the secret code word, "dead head," after viewing this other stackoverflow question:
Some code was lost after doing bzr commit --local, bzr pull, bzr commit
However, the solution they proposed didn't work for me. What did work, was found at
http://chrismarinos.com/don-t-loose-your-head-with-bazaar/
The final answer was to find the revision id using heads --all, and then use pull get get all the revisions:
bzr heads --all
bzr pull --overwrite -r revid:<revision-id>
All my code is back, and now backed up 3 or 4 times.
I honestly cannot say how that would have happened—it honestly looks like that would be the behavior of a (sounds pretty catastrophic bug), unless you did something like bzr pull --overwrite or did a bzr revert after a bzr pull that had conflicts.
First things first, see if you can reliably replicate this problem. Whether or not that is possible, though, file a bug report against bzr so that this issue can be tracked. Also, before doing ANYTHING ELSE AT ALL, back up the data that you have in these branches. If you have been working in a shared repository, back up the whole thing. That way it is available for forensic recovery if such drastic efforts are necessary. For more help on that, though, you'll have to work with the Bazaar developers. It might be helpful to hang out in the #bzr room on FreeNode's IRC network to ask for help. As is the usual for seeking out support on IRC, patience is key even if the situation you're in is pretty urgent. They may be able to give you some Python code or instructions on how to dig up those commits, and they also may be able to tell you how to find out what happened.
That said, what I typically do when doing development like this, is I have an unbound "upstream" branch, and then whatever branch I am working in. When I am finished with my changes, I'll pull from the upstream, merge my branch into the resulting tree, then push back up. For example:
$ bzr init-repo project; cd project
$ bzr branch bzr+ssh://example.org/srv/bzr/project/trunk trunk
$ bzr branch trunk my-feature-branch
$ cd my-feature-branch
... work, commit; work, commit; ...
$ cd ../trunk
$ bzr pull
$ bzr merge ../my-feature-branch
... resolve any merge conflicts here, if any ...
$ bzr ci -m 'Merge in my-feature-branch'
$ bzr push :parent
Doing it that way also keeps your work separate from the upsteam branch until you're ready to merge and push it. And it ensures that your local branch never has the chance to be overwritten.