Get SHA for the first commit in git repository subdirectory, using libgit2sharp - libgit2sharp

How can I look up the SHA for the first commit in a repository subdirectory using libgit2sharp ?
On the command line I would do
git rev-list --max-parents=0 HEAD

Related

How to checkout to a different branch in submodules?

We are have 2 rails projects for which /models are common for both of the projects and so we maintained a separate repo by using submodules concept.
Now in project1 I created a branch rails3_upgrade from master for my submodules i.e., in app/models.
how can I checkout to that branch in project2 models from master?
I tried get fetch --all and git remote -v and some other options but couldn't see the branch I created.
Googled but couldn't find. Can anyone tell me how can I do this?
A branch created in a parent repo project1 won't be visible by other repos (submodules or project2)
You can create that branch in a submodule of Project1, and see it in the same submodule in project2
cd /path/to/project1/submodule1
git checkout -b newBranch
git push -u origin newBranch
cd /path/to/project2/submodule1
git fetch
git checkout newBranch --track origin/newBranch
As usual, is you make any modification in a submodule, don't forget to add and commit in the parent repo as well.
Creating a branch in a submodule does not mean the submodule will always checkout the latest of that branch though.
For that, see "Git submodules: Specify a branch/tag" I wrote before.
And for the submodule to update itself to the latest of that branch, you would need a
git submodule update --recursive

Git: Merge test repository into master repository

I am new to Git/Heroku/RoR, know basics of these technologies.
I have a git repository repoA which has two branches, master and feature.
I continued working on repoA/feature and upon completion, because the changes were huge so decided to launch a separate app on Heroku to test them first.
So deployed repoA/feature to repoTest/feature on Heroku. Then made some fixes to the feature and finalized the code in repoTest/feature.
Another developer made some commits in repoA/master during this time.
Now I want to make my repoTest/feature LIVE and MERGE it to repoA/master.
Please help me how can I do that ?
NOTE: I have tried doing git rebase master but that did nothing even after a long manual conflict resolve exercise.
As below steps are my normally operations:
1. git checkout repoA/feature
2. git fetch repoTest/feature; git merge repoTest/feature repoA/feature; git stash
3. git checkout repoA/master; git pull origin
4. git checkout repoA/feature; git rebase repoA/master (maybe here you should resolve your conflicts); git stash pop
5. git status; git commit -am ""; git push origin

How to delete a folder from Bitbucket repository?

I'm a Bitbucket noob and having a hard time getting started.
I'm trying to clean up the Bitbucket repository and my local git folder master and branch organisation.
My local computer's git folder has some folders deleted via Terminal $ rm -r folderName > $ git push.
Bitbucket repository still shows the folderName. How do I remove this?
I already deleted file and commited , but files cached on bitbucket.
You need to remove the folder from your local repository with git rm -r folderName and then git commit -m 'Delete folder folderName because foo (for example) and git push.
You need to commit your changes before pushing them.
you forgot:
git commit -am "commit message"
You probably didn't do a final "git push"
Once you delete your folder locally,
git status
this shows you that a folder was deleted
git add .
this stages changes
git commit "deleted xyz folder"
git push
this final "git push" deletes the folder on remote

Pushing a branch to a remote repository in git

I'm trying to update the 3-2-stable branch on my fork of the Ruby on Rails project. So after cloning rails, I initially did a git checkout -b my_branch remotes/origin/3-2-stable. Then I made my changes. Then I added my fork as a remote repository with git remote add my_fork git#github.com:myusername/rails.git. Does a git push my_fork my_branch update the 3-2-stable branch only in my_fork? Is there something special I need to do?
Does a git push my_fork my_branch update the 3-2-stable branch only in my_fork?
Yes it will. It won't affect any other repo.
Note that the 3-2-stable on your fork won't be impacted either: a new branch my_branch will be created on your fork to reflect your local branch.
But if you want to push/pull that branch from the repo my_fork, then this would make it easier:
git push -u my_fork my_branch
See "What exactly does the “u” do? “git push -u origin master” vs “git push origin master”" for more on setting the upstream branch of a local branch.

git: how to get changes nicely back into master when working with submodules

i use the git workflow as described in this blogpost.
In short: everybody develops inside his/her own branch, before merging back to master, you rebase your branch to master again to get clean history.
This works.
Now we have a submodule, and because this is an in-house plugin (Rails), we need to change this often. So most of the times i have changes both in the general branch and in the submodule branch.
What is the best way to work with submodules in the workflow as above.
I first try to push my changes to the submodule (git checkout master, git pull, git checkout branch, git rebase master, git checkout master, git merge branch).
Then, when i try to do the same for my root, i always get an error on my plugin (submodule). I have to resolve the error, before doing git rebase --continue. So if try to git mergetool i converts my folder to a file.
After the rebase has ended, i just restore the <folder_name>.orig to overwrite the file <folder_name> and all is well.
But somehow it feels there should be a better way.
In short: when working via checkout-b/rebase/merge - workflow, how do you handle the changed submodules simultaneously?
Whatever workflow you are following with submodules, there is one rule you shouldn't forget:
(From the Git tutorial)
If you want to make a change within a submodule, you should first check out a branch, make your changes, publish the change within the submodule, and then update the superproject to reference the new commit.
$ git checkout master
$ echo "adding a line again" >> a.txt
$ git commit -a -m "Updated the submodule from within the superproject."
$ git push
$ cd ..
$ git add a # There is a gotcha here. Read about it below.
$ git commit -m "Updated submodule a."
So did you commit the new state of your submodule within the parent project before attempting your rebase/merge from said parent project?

Resources