Open Source Development

Power Open Source Development

Connect, learn, share, and engage with IBM Power.


#Power


#Power
 View Only
  • 1.  git-2.38.3-1 -- Odd behaviour when switching branches and modified file NOT committed

    Posted Fri June 16, 2023 11:52 AM

    AIX: 7.3.0.2

    Git: 2.38.3-1 (latest)

    In Git I created a branch ("steve") and switched to it before modifying a script, at this stage I have not run "git add" or "git commit".  I then switched to "main" and Git allowed to do this.

    NOTE: What does the "M" (first column second line) actually mean here?  Is it just meaning "M"odified?

    $ git switch main
    M       nim_scripts/check_hmc_IBMi.sh
    Switched to branch 'main'
    Your branch is up to date with 'origin/main'.

    The timestamp on the file in "main" has been updated and the content too.

    $ ls -la
    total 144
    drwxr-xr-x    2 mundays  emea           4096 Jun 16 09:04 .
    drwxr-xr-x    4 mundays  emea           4096 Jun 16 09:04 ..
    -rwxr-xr-x    1 mundays  emea           3519 Jun 16 11:23 check_hmc_IBMi.sh

    I then switched back to "steve" and did a "git restore"

    $ git switch steve
    M       nim_scripts/check_hmc_IBMi.sh
    Switched to branch 'steve'
    $ git status
    On branch steve
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   check_hmc_IBMi.sh
    
    no changes added to commit (use "git add" and/or "git commit -a")
    $ git restore check_hmc_IBMi.sh
    $ git status
    On branch steve
    nothing to commit, working tree clean
    $ ls -la
    total 144
    drwxr-xr-x    2 mundays  emea           4096 Jun 16 11:29 .
    drwxr-xr-x    4 mundays  emea           4096 Jun 16 09:04 ..
    -rwxr-xr-x    1 mundays  emea           3405 Jun 16 11:29 check_hmc_IBMi.sh
    

    The timestamp got updated (due to the removal of my change) and the content was also reverted back to before my change.

    Question

    Is this considered "normal behaviour" for Git as I thought that if you try to switch to an alternate branch with un-committed changes you get prompted?

    Many thanks, Steve



    ------------------------------
    Steve Munday
    AIX, IBM i, HMC, PowerVM
    ------------------------------

    #AIXOpenSource


  • 2.  RE: git-2.38.3-1 -- Odd behaviour when switching branches and modified file NOT committed

    Posted Fri June 16, 2023 01:51 PM
    Okay, put on a helmet:

    Git will let you switch branches with local changes when doing so would not clobber anything on the new branch.

    So if you are on branch1 and create branch2, there is nothing to clobber. It will switch and take the modified files with it.

    If you try to switch from branch1 to an existing branch2, with incompatible changes to working files, then git won't let you until you do something to avoid losing your work. You could commit it, to put it into the stash. Look into git stash push and git stash apply.

    These rules always work, but if you have staged files, it might not be obvious what would be included in the change set.

    -- 
    Stephen L. Ulmer
    Enterprise Architect
    Mainline Information Systems








  • 3.  RE: git-2.38.3-1 -- Odd behaviour when switching branches and modified file NOT committed

    Posted Mon June 19, 2023 04:25 AM

    Stephen,

    Hi, good morning.

    Ok, so if I've understood correctly, as I was in the "steve" branch and made changes which would merge nicely with the original script in "main" branch when I did switch to "main" (without any add/commit beforehand) that merge took place (as no issues found).  Would there have been issues when I switched then Git would have thrown up a message.

    Many thanks, Steve



    ------------------------------
    Steve Munday
    AIX, IBM i, HMC, PowerVM
    ------------------------------



  • 4.  RE: git-2.38.3-1 -- Odd behaviour when switching branches and modified file NOT committed

    Posted Mon June 19, 2023 05:14 PM
    I just want to clarify: git would not have merged for you,  it would have carried the changes to the new branch so that you could do a merge.

    -- 
    Stephen L. Ulmer
    Enterprise Architect
    Mainline Information Systems
    (m) 352-870-8649






  • 5.  RE: git-2.38.3-1 -- Odd behaviour when switching branches and modified file NOT committed

    Posted Thu June 22, 2023 05:49 AM
    Edited by Steve Munday Thu June 22, 2023 05:51 AM

    Stephen,

    Hi, good morning.

    NOTE
    The "main" and "steve" branches are on a cloned copy of the actual repo.

    Ok, so are you saying that even though, using ls -la, I "see" an updated (size/date) script having first switched "back" to main (from steve) git has NOT actually done anything to the "live" script (so running it would execute the pre-updated script) and it is not until I switch back to steve, do a git push, merge in Github, and then (on branch main) do a git pull that the "changes" being made would become executable from within the main branch?

    I guess what I'm trying to understand is why I "see" the changes (date/size) when switching back to main from steve?  Also, when back in main (and before any push to github etc.) I can cat the "changed" script and see the changes within!!

    Many thanks, Steve



    ------------------------------
    Steve Munday
    AIX, IBM i, HMC, PowerVM
    ------------------------------