Repoint git-svn master branch back to trunk - git-svn

I'm not sure how I got into this state, but my master branch on my local git-svn repo seems to be pointing to the remote UAT branch.
git status
# On branch master nothing to commit (working directory clean)
git svn dcommit Committing to https://svn...com/MyRepo/branches/UAT ...
how do I fix this?

I think what you're trying to fix is that your local "master" branch is based on the remote UAC branch, as opposed to the remote trunk. If you're happy to lose your commits, you can simply run the below, which will checkout the trunk and then move the master branch to your current point.
git checkout remotes/trunk
git checkout -B master
If you don't want to lose your commits, git rebase is your friend. Use the below:
git rebase $(git merge-base remotes/UAC master) master --onto remotes/trunk
This works out the common parent of the UAC branch and the local master branch, makes all the commits from there to the tip of the master branch onto the trunk, then moves the master branch to point there.

One way would be to rename the current master branch and to checkout origin/trunk as (new) master branch.
git branch -m master uat
git checkout origin/trunk master
If you need you can now cherry-pic commits from the uac branch to master (I would use gitk --all to help me with this)
A little more complex problem:
Rename master branch for both local and remote Git repositories

Related

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.

git-svn create svn branch from svn branch

With git-svn If I have cloned svn repository with all trunk, branches and tags, how do I create a new svn branch out of a svn branch?
I know I can create a new branch from trunk (master) with git svn branch, but how do I handle this from a branch?
SHould I first create a local tracking branch from the branch, and out of it invoke git svn branch?
I did it using a local tracking branch, and create branch from it:
git checkout master
git branch --track localToBeCloned BranchToBeCloned
git checkout localToBeCloned
git svn branch NewClone -m "new branch created"
git branch --track localNewClone NewClone
git checkout localNewClone

Ignore git-svn files from `git log`

Is there a way to ignore git-svn updates? my usual workflow:
doing stuff in my dev git branch
checking out my master
git svn rebase on master
cherry-pick from dev
git svn dcommit
checkout dev again
git merge master
the only problem with this is that after i git merge master, i do git log -n ###, and i get all the git-svn updates as well. Can i limit it just the latest git commits?
No, you can't merge master back into the dev-branch without getting the git-svn commits along for the ride.
The thing is that when you do a git svn dcommit, you actually rewrite the commits that you've cherry-picked from the dev branch. The git-svn commits are now part of your history, and it would be folly to try to get rid of them some how. If I'm guessing correctly, your dev branch is full of merge commits where your git-svn commits are re-joined with your dev-commits because they have diverged. This is messy.
That being said, I'm also unsure if your workflow is optimal. Maybe you should try this:
work work work in the dev branch
git svn rebase on master for the lastest svn changes
Now rebase these latest changes in under your work: git rebase master in dev
Now fast-forward your changes back to master: git merge dev on master
git svn dcommit on master
Now remove the dev branch. Little sense in keeping it since the commits have now been rewritten by dcommit. git branch -d dev
git checkout -b dev for the next feature/fix.

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