Merge in git after taking

I use the following hook after taking:

GIT_TOP=`git rev-parse --show-toplevel` while read oldrev newrev refname do echo "=== $oldrev" echo "=== $newrev" echo "=== $refname" echo "=== 01. checkout -- $GIT_TOP/*" git checkout -- "$GIT_TOP/*" echo "=== 02. merging $refname" git merge $refname echo "=== 03. checkout -- $GIT_TOP/*" git checkout -- "$GIT_TOP/*" done 

The idea is clear enough: I want the current branch to be merged with the pressed one.

  • Then I execute: git status , and it shows me that my local tree is different from the branch!

  • The more I do git checkout -- * at the top of git dir - and now this command does what I want: git status no longer shows the differences.

Why did this git checkout -- "$GIT_TOP/*" command git checkout -- "$GIT_TOP/*" not work and only work with a direct call? How to run this command in hook?

PS

I found that git rev-parse --show-toplevel , called from inside the hook, returns the path <myrepo>/.git , but from the shell its value is <myrepo> . Perhaps this will help solve the problem.

+4
source share
3 answers

export GIT_WORK_TREE=$GIT_DIR/. solved my problem. Now even git checkout -- "$GIT_TOP/*" no longer needed. Because git merge $refname working correctly - in the correct directory.

+2
source

OK, now it works. Think more, copy less.

 export GIT_WORK_TREE=`pwd` export GIT_DIR=`pwd`/.git 

Floor

+3
source

thanks for that.

I tried this:

 export GIT_WORK_TREE=$GIT_DIR/. while read oldrev newrev refname do echo "=== merging $refname" git merge $refname done 

an error appeared: "Your local changes in the following files will be overwritten by merging" .. the mention of the file was simply clicked.

This suggests that he is not trying to merge the change he just received into the main branch.

Perhaps you need a validation wizard?

I was able to perform the merge manually.

Floor

+1
source

All Articles