Using the Rugged gem, I want to obtain all commits in all branches, similar to this git command line:
$ git log --all
Walker requires a branch, so the following only works for the specified branch:
repo = Rugged::Repository.new(working_dir)
walker = Rugged::Walker.new(repo)
walker.sorting(Rugged::SORT_DATE)
walker.push(repo.branches['master'].target_id)
walker.each do |commit|
# do stuff
end
walker.push seems to be a requirement for walker to return a value, but I do not want to filter out any branches.
Related
I want to write a shell program to check whether all go module dependencies in my project are on newest master version in their repositories. In particular, I want to know which branch each module is on. There is a file "go.mod" containing each dependency listed as {module}-{commit time}-{commit ID}. How can I get their git-branch name from SHA-1(commit id) or other message by shell program.
I have tried go list -m -u all, only showing the newest edition if the dependency is not up-to-date. etc. git.xxx.com/project v0.0.0-20191119034146-e894bf51bdcd [v0.0.0-20200609070643-fd412b12b811]. Without cloning the repos, can go module tools resolve this quetion?
I couldn't figure out how to find which branch the current dependency belongs to using only go tools. But there is a way to find which branch the commit is on using git.
git clone <repo-url> && cd <repo> && git branch -a --contains <commit>
Reference: Finding what branch a Git commit came from
I want to install mongoDB-driver. When I type this command
go get go.mongodb.org/mongo-driver/mongo
I got :
# cd /Users/jiangwei/go/src/go.mongodb.org/mongo-driver; git pull --ff-only
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
package go.mongodb.org/mongo-driver/mongo: exit status 1
Probably because you've already checked out that repo into your Go path, and have changed to a non-default branch. The simplest way to correct it would be to remove that repo, and start from scratch.
rm -rf $(go env GOPATH)/src/go.mongodb.org/mongo-driver
Of course, this will lose any changes you've made in that repo.
Im very new to Git and what I want to do with git within xcode is pull an older revision of my master (not commandline). Is this possible? I've looked in repositories under the organizer and i see all my commits there but i cant seem to load in one of them.
You can't go back to an earlier version of a repository from Xcode in Xcode 4. Older versions of Xcode allow you to go back to an earlier version of a repository, but older versions of Xcode lack git support.
I think that if you have cloned/pushed your repo all the stuff you need is on your local drive.
If you want to see how code looks in specific commit, do
git checkout branch_name
or
git checkout 14646bf1a76d08cbda99317c4faa8de0072d6975
where branch_name can be alias for checksum used by git, (like master or origin/master), if you want to list your branch checksums you can do that by
git log
or if you want it in GUI use qgit gitg or my favourite tig, or whatever you'll find to list your commits
I have an iOS project in Xcode 4, that is using Git. Now I want to add the MKStoreKit framework to my project. It is already under version control using Git and a public repo. I'd like to include it in my project, and allow my project's git version control to do version control of the currently pulled version of MKStoreKit, while maintaining the ability to clone any updated MKStoreKit code with standard git ease. I see that a git submodule or subtree is probably what I need, but it seems like a real PITA. Is there not a simpler way?
So far any external code I add to my project I clone to a temp directory, then copy the individual files into my project. This feels like a kludgy way to do things.
Check out the submodules section of the Git book. They're not really all that bad.
If you have a git repository, and you want to add another repository as a subdirectory, you can do this:
git submodule add git://github.com/MugunthKumar/MKStoreKit.git mstorekit
Now you have a directory "mstorekit" inside your project that is actually the MStoreKit repository. If someone clones your repository, they'll start with an empty "mstorekit" directory. Running:
git submodule init
git submodule update
Will clone the MStoreKit repository. They'll end up with the HEAD of the MStoreKit repository at the same commit as the one checked in to your repository.
Updating MStoreKit would look like this:
cd mstorekit
git pull origin master
cd ..
git ci -m 'updated mstorekit to latest version'
There are some alternatives out there, including git-subtree, which I saw mentioned recently around here. I have no experience with it (whereas I've been reasonably happy working with submodules).
I have been trying to use the ruby-git gem to make commits etc from with in a ruby script however the method to check the current status always throws an error. My understanding is that this code, although not doing too much, should be valid.
#gem install git
require 'rubygems'
require 'git'
g = Git.init
g.status
but it returns:
Git::GitExecuteError: git diff-index "HEAD" 2>&1:fatal: ambiguous argument 'HEAD': >unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/lib.rb:700:in command'
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/lib.rb:672:incommand_lines'
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/lib.rb:287:in diff_index'
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/status.rb:99:inconstruct_status'
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/status.rb:8:in initialize'
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/base.rb:175:innew'
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/base.rb:175:in `status'
from (irb):5
Does any one have examples of how to get the current git status within ruby (using ruby-git)?
Pages I have looked at:
http://rubygems.org/gems/git
http://git.rubyforge.org/
Thanks
I can't answer the question of how to get the status if no commits have been made, but I can try and explain why it's blowing up.
The Git::Status class works by doing a git diff of HEAD against the repository. In Git "HEAD" refers to the current branch & working tree.
Since a branch is basically a pointer to a particular commit (the branch pointer gets moved along the history as new commits are made) no branches truly exist (not even master) until there is a commit to point it at. If there are no branches, HEAD doesn't really exist either. Therefore referring to it in a git diff throws an error.
This is a great visual guide to understanding HEAD/branches/commits: http://marklodato.github.com/visual-git-guide/
So in conclusion, it seems that trying to do anything in a git repo which has no commits is somewhat meaningless. Of course, to do a commit, you need a file. So you probably need to:
#gem install git
require 'rubygems'
require 'git'
#Create an empty file
FileUtils.touch 'README'
g = Git.init
g.add('README')
g.commit('First Commit')
g.status
If you want to check if a file has been added to the repo:
#gem install git
require 'rubygems'
require 'git'
#Create an empty file
FileUtils.touch 'README'
g = Git.init
g.ls_files.has_key?("README") #False
g.add("README")
g.commit("First Commit")
g.ls_files.has_key?("README") #True
Path may be the important bit of that error message
unknown revision or path not in the working tree.
I tried running:
$ irb
> require 'rubygems'
> require 'git'
> g = Git.init
> g.status
in a directory that has no git repo, and it blew up like yours did.
After cding into the root directory of a project with a git repo, it worked.
Check that you are in the root of a git repo. There should be a .git directory in it. If not, you could also pass the path to Git.init if cding is inconvenient for some reason.