如何设置git主分支以忽略本地文件而不是全局文件(如果已经在git索引中)

如何设置git主分支以忽略本地文件而不是全局文件(如果已经在git索引中),git,Git,本次讨论的问题在-,您必须执行吗 我有什么问题- $ 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 up

本次讨论的问题在-,您必须执行吗

我有什么问题-

$ 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
我明白了--

$ 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
所以我的问题是,我要倒转吗

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

下一个

我问这个问题是因为我正在为一个文件而与“git pull”和“git checkout”进行斗争,这让我发疯。

我的开发团队和大多数其他团队使用的当前git工作流是使用主分支作为默认分支,并构建和部署aka CI/CD分支。但是,只有团队负责人有权进入master。因此,开发人员从master创建所有分支,并执行git add[filename]或。和git commit-m'User Story XYZ',然后git推送到remote并创建一个PULL请求

但是,在这种情况下,我们必须确保所有开发人员都有自己的本地配置文件,并且确保没有部署它们。更好的是,如果它们最初被添加并提交到主分支,会发生什么?希望本指南能对您有所帮助

有问题的文件是.config文件,不应忽略这些文件,但每个开发人员工作站都需要更改这些文件

警告—在执行这些步骤之前创建的以前的分支之间来回出现问题

关键是确保您位于主分支上,并运行以下git命令

 git checkout master

 git pull

 git status
你想确保你有一个干净的工作树

2个步骤-如果要忽略的文件从未添加到GIT本地存储库中

添加到排除文件。如果使用windows,请打开windows资源管理器,并确保取消隐藏隐藏的文件,并导航到我们使用的windows中您的回购位置:

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

注意:需要使用您选择的记事本或记事本文本编辑器打开排除文件++

跑步

 git add <filename>
采用与上述相同的格式: 注意排除是一个需要用记事本或记事本打开的文件++

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



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

您可以使用git pull更新本地分支,或者执行git获取,这样就不会立即应用修改。可能吗?如果有必要,做一个git隐藏,这样你就不会丢失你的工作。首先,我必须运行“git更新索引-无跳过工作树”来再次查看文件。然后我运行了“git stash”,我能够运行“git pull”。这是否意味着我将不得不运行“git stash pop-index stash”{}如果这是真的,那将是一种痛苦。是你自己造成的痛苦。不要提交应用程序配置。看看如何做对:坚持“博士”——我没有把它强加给我,我是团队中许多人中的一员。我没有做原始添加。并承诺,只是试图解决问题。谢谢你的链接。
git update-index --skip-worktree <filename>. 
 git checkout master

 git pull

 git status
 git add <filename>
 C:\Users\USERNAME\Source\repos\SolutionName\.git\info\exclude 
 C:/Users/USERNAME/Source/Repos/SolutionName/{filename}



git add <filename> 
git committed -m 'Committing my files to GIT index'
git update-index --skip-worktree <filename>
 git ls-files -i --exclude-from=C:/Users/USERNAME/source/repos/SolutionName/.git/info/exclude