Git checkout to new branch but HEAD is still from old branch

Viewed 32

I have code which do some checking( diff master with branch and diff HEAD^ HEAD) and if object in diff master with branch exist in diff HEAD^ HEAD do some stuff

Code:

if ! [ -d $PROJECT/\.git ]; then
            echo "Cloning project"
            git clone $REPO $PROJECT
        fi
        
        #Fetch updates
        echo "fetching updates"
        git -C $PROJECT fetch --all
        strTmp=$(git -C $PROJECT diff origin/$BRANCH..origin/master --name-only)
        echo "strTmp = $strTmp"

        if [ -n "$strTmp" ]; then
                
            git -C $PROJECT reset --hard
            git -C $PROJECT checkout $BRANCH
            git -C $PROJECT pull
            lastRev=$(git -C $PROJECT diff HEAD^ HEAD --name-only)
            
            array=(`echo $lastRev | sed 's/,/\n/g'`)
            changed="0"
            for i in "${!array[@]}"
            do
                echo "$i=>${array[i]}"
                if [[ $strTmp == *"${array[i]}"* ]]; then
                    changed="1"
                    break
                fi
            done

In one branch i found out this:

** HEAD is now at 2c9db21e2

Merge remote-tracking branch 'origin/master' into release/144

Branch 'release/152' set up to track remote branch 'release/152' from 'origin'.

Switched to a new branch 'release/152'

Merge made by the 'recursive' strategy.

_TUN.env | 47 ++++++

_TUN.dev | 175 +++++++++++++++++++++

_CLN.dev | 57 +++++++

3 files changed, 279 insertions(+)

create mode 100644 _TUN.env

create mode 100644 _TUN.dev

create mode 100644 _CLN.dev

0=>_TUN.env

1=>_TUN.dev

2=>_CLN.dev **

So we successfully switched to new branch release/152 but files ( and HEAD i think)still from release/144.

And because of this script think nothing changed in this branch(changed=0).

Question is why after we checkout to the new branch files still from old branch?

Maybe i miss something?

0 Answers
Related