git svn status - showing changes that are not committed to svn - git-svn

I'm looking for a command in git-svn that will show me the changes I have committed to my git repository but that aren't yet committed to the central svn repository. I'm looking for something that works like svn status, but I'm using git-svn, and unfortunately, git svn status is not a valid command.
I tried git status but it does not solve this problem, as it shows changes that haven't been committed to my local git repo.
I also tried git svn dcommit --dry-run, but it doesn't tell me which files are ready to be dcommitted - it only shows the repository URL.

Assuming the branch for the remote Subversion repository is at remotes/git-svn, run the following:
git svn fetch
The fetch will ensure that remotes/git-svn is up-to-date. (Thanks to Mark for pointing this out in a comment.)
git diff --name-status remotes/git-svn
This should show you the name and status of all the files that have been committed to git but not to Subversion, just like the svn status command.
In case you're not sure where the branch containing the Subversion remote repository is located, you can run:
git branch -a
which should produce output similar to the following:
* master
remotes/git-svn
You can probably guess from this that the remote Subversion repository is in remotes/git-svn.

You can also use
git diff git-svn HEAD -d
or if you have difftool specified:
git difftool git-svn HEAD -d

Related

Command to show branch being tracked and revisions behind by git svn

I just want to know to what I am pushing when I use git svn dcommit and from what I am pulling when I git svn rebase.
Is there a commandline command I could execute that would give me that information? I just want the branch name.
Also, is there any way to see how many revisions I'm behind or ahead with git svn?
Thanks!
Try a dry run: git svn dcommit --dry-run, same for rebase.

Recover git-svn mirror after svn repository was "rolled back"

How can i repair my git-svn mirror repository?
It is set up with git svn init ..., then github remote was added. The cron job is doing git svn rebase && git push periodically.
Everything was fine until upstream somehow "uncommited" several revisions from svn, which already was fetched into my git-svn and pushed to github. Then upstream added some new revisions to svn trunk, reusing revision numbers of "uncommited" revisions, which broke my syncronization process.
When i realized what hppened, i did git svn reset to last valid revision and commited reverse patch into git.
But since then, i can not pull upstream changes with git svn rebase, i have to do git svn fetch && git merge trunk instead, resulting in awful history.
Can i somehow tell git-svn that i will not git svn dcommit anything, that it can forget about that reverse patch commit, so git svn rebase can work like it worked before all this happened?
My investigation results: there is nothing magical in git-svn's rebase function. It is just a git svn fetch followed by git rebase refs/remotes/trunk and refs update.
In my case, all i had was to move my local tracking branch ref to the last fetched from commit.
git svn fetch
git log -1 refs/remotes/trunk
gave me latest sha1: ed0fa874ca872bc3a0101ee397f611a537e72c2a
git update-ref HEAD ed0fa87
git reset --hard
Useful resources: Pro GIT Book, Visualizing branch topology in git.
Hope, this will help someone.

How to import local git repository into svn?

I am working on local git repository and I need to push my local git into existing svn repository. My git repository is pure local git repository, it was not init using git svn clone.
How can I import this local git repo into svn?
Preferably I'ld like to keep the git history being imported into SVN.
Currently the SVN repository is structure as:
https://svnrepohost
/branches
/tags
/trunk
/projectA
/projectB
/newProject
What I need it is to import my git repository into the https://svnrepohost/trunk/newProject above, assuming the newProject folder is empty.
I have finally solved this problem by the following steps:
Setup appropriate project folder in svn to be imported to, for example http://svnrepo/svn/trunk/newProject
Create a new git-svn repository
git svn clone http://svnrepo/svn/trunk/newProject
Add the git repo that we want to import as remote to the new git-svn repo
git remote add origin ../original-git-repo
Pull all the data from original-git-repo
git pull origin master --allow-unrelated-histories
Rebase local repository against svn
git svn rebase
Commit the changes into svn
git svn dcommit
Clean up the remote
git remote delete origin
The easiest way to do this is to just svn import the Git directory. That will lose you your Git commit history, however.
First of all, make sure the .git directory won't be imported by setting the global-ignores in the Subversion config file. Open your ~/.subversion/config file (that'll be in something like C:\Users\username\.subversion\config on Windows), find the section starting [miscellany], and add a line directly underneath reading as below:
global-ignores = .git
(if you already have a line with global-ignores = that doesn't have a # in front of it, then just add .git to the end of that line.)
Next, run the below:
svn import <path-to-local-git-repository> https://svnrepohost/trunk/newProject
That should copy the contents of the local Git repository onto the server exactly where you want it.
You may use SubGit.
$ svnadmin create repo.svn
$ subgit configure repo.svn
...
CONFIGURATION SUCCESSFUL
Adjust '/tmp/repo.svn/conf/subgit.conf' file
and then run
subgit install "repo.svn"
to complete SubGit installation.
$ nano repo.svn/conf/subgit.conf #edit to set git.default.repository=path/to/your/bare/git/repository
$ subgit install repo.svn
I would also recommend you to create a bare clone of your Git repository and to specify path to it (in git.default.repository) instead of your original repository. I.e.
$ git clone --bare path/to/your/original/repository path/to/your/bare/git/repository
After "subgit install" command the repositories (repo.svn and repo.git) will be in continuos synchronization (triggered by pre-receive hook in Git [that starts on pushing to your bare repository] and pre-commit in SVN). To stop synchronization you may run
$ subgit uninstall repo.svn
git svn clone http://svnrepo/svn/trunk/newProject
git remote add origin ../original-git-repo
git fetch origin
git checkout -b lmaster remotes/origin/master
git rebase master
git svn rebase
git svn dcommit

How to recreate a git svn remote tracking branch?

I'm using git as an interface to an SVN repository. Now I've created a SVN branch:
git svn branch my_branch
This created the directory in my SVN repository, and also created a branch called remotes/my_branch. Then I've deleted that remote tracking branch:
git branch -r -d my_branch
Now the directory is still there in the SVN repository, but I can't seem to find a way to get the remote tracking branch back. Any idea? I tried
git svn branch my_branch
=> branch test_new_mod_named already exists
and played around with git svn reset, etc. to no avail.
The easiest way I found to be making a commit in my_branch using svn, and then doing another git svn fetch.
$ git svn branch my_branch
Copying file:///Users/tfnico/svn-repo/website/trunk at
r14 to file:///Users/tfnico/svn-repo/website/branches/my_branch...
Remote branch is there:
$ git branch -a
master
* trunk
remotes/my_branch
Delete branch:
$ git branch -r -d my_branch
Deleted remote branch my_branch (was d422fbd).
And branch is gone. Now try a git svn fetch to recreate it:
$ git svn fetch
Nothing happens, until somebody does this...
$ svn checkout file:///Users/tfnico/svn-repo/website/branches/my_branch/
... and makes a commit. Voila:
$ git svn fetch
M hotfix.txt
r19 = f7449780fbb653cbcbc09861c0b446d41321e3f5 (refs/remotes/my_branch)
[17:29:33] tfnico:~/sources/git/website/[trunk]>git branch -a
master
* trunk
remotes/my_branch
Remote branch is back.

How to update 'git log' after 'git svn fetch' on a bare repo?

I have a bare git-svn repository and did a 'git svn fetch' on it.
Running 'git log' doesn't show the updates. I'm sure there are updates as it displayed the files changed after 'git svn fetch' and 'git svn log' shows them also.
Please note that I purposely made this a bare repo so 'git rebase' will not work.
What is the appropriate command to get the fetched changes?
A git svn fetch adds a new remote branch called remotes/git-svn (as can be seen with git branch -a).
If you make changes to the upstream svn, then run git fetch again, the changes get pulled (actually, fetched) in on this branch, not on master.
So to make git log (and everything else) work ok on the master branch you just need a merge, as you normally would have to do after a fetch (this is what git pull does, a fetch and then a merge).
Since git svn pull does not work, you will have to merge it manually. While on the master branch, run:
git merge remotes/git-svn
This will merge your master branch with the git-svn branch, making everything ok again.
So in the future, run
git svn fetch
git merge remotes/git-svn
and you will be up to date with the upstream repository once again.
Setting the ref of master's head to git-svn head as suggested by vjangus will also make this work, but you shouldn't ever be making changes in a remote branch.
Try git log git-svn - I don't have a bare repo, but I've just run git svn fetch, and standard git log gives me the current (rebased) log, but with the git-svn arg (which is the other branch besides master that is identified by git branch -a in my case) I get the log up to the fetched revision
I found the answer,
git symbolic-ref refs/heads/master refs/remotes/git-svn
Thanks to Steven Walter's comments in
http://gsocblog.jsharpe.net/archives/12