简体   繁体   中英

Is it safe to 'git svn dcommit' commits out of order

I am working in a project that has a master subversion repository.

I have started to use a local git repo together with the git-svn bridge. My workflow is:

  • Take updates into master using git svn rebase
  • Before working on a bug, make a branch with git checkout -b XXXXX
  • Commit changes to the branch
  • Merge the branch into master
  • git svn dcommit to push changes from master back to the remote SVN repo

At the moment, I have a couple of changesets that have been merged into master but not yet dcommitted back to SVN. I can't push these just yet because they are waiting on other dependencies, but meanwhile I need to push out another urgent fix.

git log in my master now looks something like this:

* 5ac10e3 (HEAD, master, b11859) Bug#1234: Urgent Bug Fix
* 2c0f704 Bug#1001 Some Large Feature
* beb3e0c Bug#1002 Another Large Feature
* c84efc2 (origin/trunk) Bug#1003 Already committed stuff

I want to dcommit 5ac10e3 but hold off on 2c0f704 and beb3e0c until sometime later.

It looks like I can could git svn dcommit --interactive and then answer 'yes' only for the commits I would like to make now. But would I be able to re-run that command and dcommit the earlier commits later? And would it be safe to do so?

If not, what is the best workflow to be using? I have a suspicion that I should not have merged those two commits into master until I was ready to dcommit them to svn.

I am wary of warnings I have read online about the need to maintain a linear git history to avoid messing up the svn repo.

I am working on Centos 7 with git 1.8.3.1.

UPDATE : git log --graph --decorate (as requested by @schwern)

* commit 5ac10e3937ef4e5b95823c73e03c893bd29b22f5 (HEAD, master, b11859)
| Author: harmic <harmic@xxxxxxxxx>
| Date:   Tue Oct 23 15:23:21 2018 +1100
|
|     Bug#1234: Urgent Bug Fix
|
* commit 2c0f7046282d4b84650b9d3a05382ad245755496
| Author: harmic <harmic@xxxxxxxxx>
| Date:   Tue Oct 23 13:36:58 2018 +1100
|
|     Bug#1001 Some Large Feature
|
* commit beb3e0c85d55450a248a277230f6a3fbbc5dc529
| Author: harmic <harmic@xxxxxxxxx>
| Date:   Mon Oct 22 12:12:17 2018 +1100
|
|     Bug#1002 Another Large Feature
|
* commit c84efc25bd9d526dafb9090a2b03fc7cfca46edd (origin/trunk)
| Author: eharmic <eharmic@44605e08-610d-0410-9c87-3f595476ec80>
| Date:   Wed Oct 24 03:38:39 2018 +0000
|
|     Bug#1003 Already committed stuff
|
|     git-svn-id: svn://svn.company.com/proj/trunk@13941 44605e08-610d-0410-9c87-3f595476ec80
|

I haven't used git-svn in a long time, but the technique for untangling mixed up commits should be the same. Just replace push with dcommit .

At the moment, I have a couple of changesets that have been merged into master but not yet dcommitted back to SVN. I can't push these just yet because they are waiting on other dependencies, but meanwhile I need to push out another urgent fix.

Just as you would in Git, undo the merge. Then put your urgent fix onto master . Now that the urgent fix is separated from other work you can push master .

Looking at your repo there is no merge commit, the merge must have been a fast-forward.

First, get rid of b11859 . It will just keep old commits alive while we shuffle things around. It's just a label. We'll recreate it later.

git branch -d b11859
git log --graph --decorate --all

* 5ac10e3 (HEAD, master) Bug#1234: Urgent
* 2c0f704 Bug#1001
* beb3e0c Bug#1002
* c84efc2 (origin/trunk) Bug#1003

We want that urgent fix to be right after origin/trunk so we can dcommit it without all the rest.

Simplest thing to do is an interactive rebase to reorder the commits in master.

git checkout master
git rebase -i origin/trunk

This will bring up an editor like so:

pick e881c96 Another large feature
pick c96a462 Some Large Feature
pick f848cca Urgent

# Rebase ba50aa8..f848cca onto ba50aa8 (3 commands)
#
# Commands:
...a bunch of instructions you should read...

Those are the commits on master since origin/trunk from first to last. You literally reorder them in the editor to your liking. We want Urgent to be first.

pick f848cca Urgent
pick e881c96 Another large feature
pick c96a462 Some Large Feature

Then save and quit. Your commits will be reordered. If there are any conflicts, fix them and follow the instructions.

git log --graph --decorate --all

* c96a462 (HEAD, master) Bug#1001
* e881c96 Bug#1002
* f848cca Bug#1234: Urgent
* c84efc2 (origin/trunk) Bug#1003

Now we need to move master back to the Urgent commit. First, recreate the old branch to keep their commits alive.

git branch old_branch
git log --graph --decorate --all

* c96a462 (HEAD, master, old_branch) Bug#1001
* e881c96 Bug#1002
* f848cca Bug#1234: Urgent
* c84efc2 (origin/trunk) Bug#1003

Then move master back to the Urgent commit.

git branch -f master f848cca
git log --graph --decorate --all

* c96a462 (HEAD, old_branch) Bug#1001
* e881c96 Bug#1002
* f848cca (master) Bug#1234: Urgent
* c84efc2 (origin/trunk) Bug#1003

Now that the other changes have been removed from master you can push/dcommit just your urgent bug fix from master .

Once that's done you can merge old_branch into master again and start b11859 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM