0

Question to this discussion found at - Git - Difference Between 'assume-unchanged' and 'skip-worktree', do you have to perform

What I am having trouble with -

$ git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   Path/Path.Private/Web.config
        modified:   Path/Path.Public/Web.config

How do I fix this because if I run

git update-index --skip-worktree Path/Path.Private/Web.config
git update-index --skip-worktree Path/Path.Public/Web.config

I get ---

$ git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

nothing to commit, working tree clean

So my question is do I reverse

git update-index --no-skip-worktree Path/Path.Private/Web.config
git update-index --no-skip-worktree Path/Path.Public/Web.config

THEN

git add <filename>'

next

git commit -m 'message'

next

git update-index --skip-worktree <filename>. 

I am asking because I am fighting with 'git pull' and 'git checkout ' over one file and it is driving me nutz.

Moojjoo
  • 729
  • 1
  • 12
  • 33
  • 1
    You may use `git pull` to update your local branch or do a `git fetch` so you don't apply the modifications right away. Is it possible? If necessary do a `git stash` so you don't lose your work. – ignacio Dec 11 '19 at 19:45
  • First I had to run 'git update-index --no-skip-worktree ' to see the file(s) again. Then I ran 'git stash' and I was able to run 'git pull'. Does this mean I am going to have to run 'git stash pop --index stash@{#}' What a pain if this is true. – Moojjoo Dec 11 '19 at 20:27
  • 1
    You inflicted the pain yourself. Do not commit application configs. See how to do it right: https://stackoverflow.com/a/3318202/7976758 and https://stackoverflow.com/a/1397180/7976758 – phd Dec 11 '19 at 21:36
  • Hold on 'phd' - I did not inflict it on me I am one of many on the team. I did not do the original add . and commit, just trying to get the issue resolved. Thank you for the links. – Moojjoo Dec 12 '19 at 16:39

1 Answers1

0

The current git workflow my development team uses and most other teams are following are to use the master branch as the default and BUILD and DEPLOY aka CI/CD branch. However, only the TEAM LEAD has the authorization rights to PULL into master. So developers create all branches from master and perform the git add [filename] or . and git commit -m 'User Story XYZ', then git push to remote and create a PULL REQUEST.

However, in this situation, we have to ensure all developers have their own local configuration files and ensure they are not deployed. Better yet what happens if they were originally added and committed to the master branch? Hopefully, this guide will help you.

The files in question are the .config files, which should not be ignored, but need to change per developer workstation.


WARNING --- YOU WILL HAVE ISSUES GOING BACK AND FORTH TO PREVIOUS BRANCHES THAT YOU CREATED BEFORE YOU PERFORM THESE STEPS


The key is to ensure you are on your master branch and run the following git commands.

 git checkout master

 git pull

 git status

You want to ensure you have a clean working tree...

2 Steps - If the files you want to ignore have never been added to the GIT local repository

  1. Add to the exclude file. If using windows open windows explorer and be sure to unhide hidden files and navigate to your repo location in windows we use:

    C:\Users\USERNAME\source\repos\SolutionName\.git\info\exclude

(Note: The exclude file needs to be open with a text editor of your choice Notepad or Notepad++)

The run

 git add <filename>
  1. Add the files you need to ignore only as you do the .ignore file, but this is used for your personal developer workstation. Give the full path to the file.

    C:/Users/USERNAME/Source/Repos/SolutionName/{filename}

IF YOU ALREADY HAVE FILES THAT HAVE BEEN ADDED AND COMMITTED AS SHOWN BELOW FOLLOW THESE STEPS

ADD THE FILES To ---

 C:\Users\USERNAME\Source\repos\SolutionName\.git\info\exclude 

Following the same format as above: (Note exclude is a file you need to open with NotePad or NotePad++)

 C:/Users/USERNAME/Source/Repos/SolutionName/{filename}



git add <filename> 
git committed -m 'Committing my files to GIT index'

HOWEVER, GO BACK TO GIT AND RUN THE FOLLOWING IF THE FILES HAVE BEEN ADDED AND COMMITED BEFORE

git update-index --skip-worktree <filename>

Repeat as needed for the files you want to ignore.

If all else fails using the following

git update-index --no-skip-worktree Solutions/Project/Web.config

git stash push Solution/Project/Web.config --message "Stashing Web.config"

git update-index --skip-worktree Solutions/Project/Web.config

After a pull, if overwrite your <file> you have the file stashed. Retrieve by either command below:

git stash pop

`git stash apply' To keep a copy in stash

Start branching and all should be good in the world. I will come back and provide an update based on this discovery work.

Happy GIT'ing........................

To validate you can run the following Git Command

 git ls-files -i --exclude-from=C:/Users/USERNAME/source/repos/SolutionName/.git/info/exclude
Moojjoo
  • 729
  • 1
  • 12
  • 33