简体   繁体   中英

Git `revert` in master deleting branch files if merged or rebased

I did something really stupid using revert and I don't know how to fix it properly. I'll try to explain clearly.

I wanted to add foo , bar and baz in a project repository. For some reasons (because I'm an idiot), I did the following mess (where "-xxx_commit" is a git-revert of "+xxx-commit"):

foo_branch
    +foo_commit 1

bar_branch
    +foo_commit 1
    +bar_commit 2
    -foo_commit 3

baz_branch
    +foo_commit 1
    +bar_commit 2
    -foo_commit 3
    -bar_commit 4
    +baz_commit 5

Then, foo_branch and baz_branch has been merged in the upstream repository... Therefore:

upstream/master
    +foo_commit 1
    +foo_commit 1
    +bar_commit 2
    -foo_commit 3
    -bar_commit 4
    +baz_commit 5

So now, foo has been added, then deleted, and I can't merge or rebase upstream/master from bar_branch because it revert itself...

Have you any idea to clean that mess ? Is there a git-idiot command or something like that ?

What about reverting, in the master -foo_commit 3 and -bar_commit 4 (the reverts of foo and bar), to get back foo and bar? You should end with foo, baz and bar in your repo. Here a trace of a example of the situation (if I got it right):

ghislain@debian: /tmp/git-test (master)
> git history 
*   a3ca029  (HEAD, master) - Merge branch 'baz_branch' (2 seconds ago) 
|\  
| * db33181  (baz_branch) - baz_commit (17 seconds ago) 
| * 618b704  - Revert "bar_commit" (32 seconds ago) 
| * 672b77c  (bar_branch) - Revert "foo commit" (51 seconds ago) 
| * 06230db  - bar_commit (62 seconds ago) 
* |   90ba017  - Merge branch 'foo_branch' (7 seconds ago) 
|\ \  
| |/  
| * 60ea014  (foo_branch) - foo commit (79 seconds ago) 
|/  
* 0b863fe  - initial (4 minutes ago) 
ghislain@debian: /tmp/git-test (master)
> git merge --no-ff bar_branch 
Already up-to-date.
ghislain@debian: /tmp/git-test (master)
> ll
total 0
-rw-r--r-- 1 ghislain fuse 0 Jul 23 15:18 baz
-rw-r--r-- 1 ghislain fuse 0 Jul 23 15:14 README
ghislain@debian: /tmp/git-test (master)
> git revert 672b77c 618b704
[master 88af7cd] Revert "Revert "foo commit""
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 foo
:[master d2cf0a3] Revert "Revert "bar_commit""
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 bar
ghislain@debian: /tmp/git-test (master)
> ll
total 0
-rw-r--r-- 1 ghislain fuse 0 Jul 23 16:37 bar
-rw-r--r-- 1 ghislain fuse 0 Jul 23 15:18 baz
-rw-r--r-- 1 ghislain fuse 0 Jul 23 16:37 foo
-rw-r--r-- 1 ghislain fuse 0 Jul 23 15:14 README

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