git-plugin icon indicating copy to clipboard operation
git-plugin copied to clipboard

[JENKINS-70195] submodule error: Your local changes to the following files would be overwritten by checkout

Open jenkins-infra-bot opened this issue 3 years ago • 0 comments

I use pipline

 checkout([
$class: 'GitSCM', 
 userRemoteConfigs: [[url: env.GIT_PATH, credentialsId: 'loongle' ]],  
 branches: [[name: 'main']],
 doGenerateSubmoduleConfigurations: false,
  extensions: [[
  $class: 'SubmoduleOption',
   disableSubmodules: false,
   parentCredentials: true,
   recursiveSubmodules: true,
   reference: '',
   trackingSubmodules: false]], 
   submoduleCfg: []
])

First time normal execution after project creation,if i update the submodule, then it will have the following error

hudson.plugins.git.GitException: Command "git submodule update --init --recursive modules/data-management" returned status code 1:
stdout: 
stderr: error: Your local changes to the following files would be overwritten by checkout:
	Yoofast.HuarenSport.DataManagement.sln
	src/Yoofast.HuarenSport.DataManagement.Domain/Yoofast.HuarenSport.DataManagement.Domain.csproj
Please commit your changes or stash them before you switch branches.
Aborting
Unable to checkout 'd352127edb42899e53550635530c396d1257c77e' in submodule path 'modules/data-management'

I think adding a parameter: --foce solves this problem, the final execution code might look something like this

git submodule update --init --recursive  --force modules/data-management

withCredentials cannot be used because there is no user name and password

withCredentials([gitUsernamePassword(credentialsId: 'my-credentials-id',
 gitToolName: 'git-tool')]) {
  powershell 'git push'
}

Originally reported by loongle, imported from: submodule error: Your local changes to the following files would be overwritten by checkout
  • status: Open
  • priority: Minor
  • component(s): git-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 2025-12-02
Raw content of original issue

I use pipline

 checkout([
        $class: 'GitSCM', 
         userRemoteConfigs: [[url: env.GIT_PATH, credentialsId: 'loongle' ]],  
         branches: [[name: 'main']],
         doGenerateSubmoduleConfigurations: false,
          extensions: [[
                  $class: 'SubmoduleOption',
                   disableSubmodules: false,
                   parentCredentials: true,
                   recursiveSubmodules: true,
                   reference: '',
                   trackingSubmodules: false]], 
                   submoduleCfg: []
])

First time normal execution after project creation,if i update the submodule, then it will have the following error

hudson.plugins.git.GitException: Command "git submodule update --init --recursive modules/data-management" returned status code 1:
stdout: 
stderr: error: Your local changes to the following files would be overwritten by checkout:
	Yoofast.HuarenSport.DataManagement.sln
	src/Yoofast.HuarenSport.DataManagement.Domain/Yoofast.HuarenSport.DataManagement.Domain.csproj
Please commit your changes or stash them before you switch branches.
Aborting
Unable to checkout 'd352127edb42899e53550635530c396d1257c77e' in submodule path 'modules/data-management'

I think adding a parameter: --foce solves this problem, the final execution code might look something like this

git submodule update --init --recursive  --force modules/data-management

withCredentials cannot be used because there is no user name and password

withCredentials([gitUsernamePassword(credentialsId: 'my-credentials-id',
                 gitToolName: 'git-tool')]) {
  powershell 'git push'
}

jenkins-infra-bot avatar Dec 02 '22 12:12 jenkins-infra-bot