Git Recover to generated files (automatic solution to delete / modify conflict by deleting)

I work for a company where one team constantly includes the generated executable file (and a bunch of other garbage) with each commit. Due to non-technical reasons, I have to constantly restructure our work on top of mine.

Here's what it looks like for me most days:

-----C------TNC--(their_branch) \ \----CC--(master) 

TNC (their new commits) contains:

  • some useful changes
  • a lot of trash

CC (clear hold) contains:

  • added .gitignore
  • rm a-lot-of-garbage - *

Now I want to do:

  (on master)$ git rebase their_branch 

This, of course, causes a conflict (modified, deleted). Since this is an almost daily task, I want to do it without fuss (enough to revise our entire history every time). So I tried:

  (on master)$ git rebase their_branch -s recursive -X ours 

According to the Git manual , this should cause "conflicting chunks to be automatically resolved using our version." another tree that does not conflict with our side is reflected in the result of the merger. For the binary, all the content is taken from our side. "But he doesn’t do this - he still stops and asks me to resolve the conflicts. I run the script deletion files, but it is annoying.

Can Git just force binary removal?

+4
source share
1 answer

For your particular set of circumstances, such as your side accepting all changes, including deleting files in your branch, you can go to the following lines. Generally speaking, although it is better to always allow discounts manually.

 # attempt a rebase, expect it to fail $ git rebase their_branch # take our side of all files that changed on their_branch and master branch, # expect resolution to fail for renames (renames include file deletions) still; # also note the meaning of `theirs` and 'ours' is reversed for a rebase. $ git checkout --theirs -- . # tell git that conflicts have been resolved (after we took our side) $ git add -A # explicitly take our side of all deletes $ git diff --name-only --diff-filter=UD | xargs -n1 git rm # proceed to rebase our changes, expect this to succeed $ git rebase –continue && echo "SUCCESS!" 

All this can be organized into a single command, an alias or a shell function:

 $ git rebase their_branch || ((git checkout --theirs -- . \ || (git diff --name-only --diff-filter=UD | xargs -n1 git rm) && git add -A) \ && git rebase --continue) 

If your rebase succeeds, || will avoid the excess resolution script by stopping in the very first state where your relocation will be successful, depending on the situation.

Here is an example download game to illustrate a file deletion reload,

 # their_branch = master, our dev branch = foo $ cd /tmp/toy-repo $ git init . && touch README && git add README && git commit -m "add README" $ git checkout -b foo && git rm README && git commit -m "rm README" $ git checkout master && echo "changing README" >> README && git add README && git commit -m "modify README" $ git checkout foo && git rebase master || ((git checkout --theirs -- . || (git diff --name-only --diff-filter=UD | xargs -n1 git rm) && git add -A) && git rebase --continue) $ git log a3730c5 rm README // on foo, rebased 55c9074 modify README // on master 1fa1398 add README // on master 
0
source

Source: https://habr.com/ru/post/1492026/


All Articles