I am using Multibranch pipeline in Jenkins. I've some pretty large project - When creating a new branch, I'd like the git plugin to only checkout new files or changed files compared to a branch
Is there a way to do that? I know once the branch exist, as long as I don't clean the workspace, it will just checkout new files and updated one, but what about new branches?
CodePudding user response:
Say you have two branches, 'old-branch' and 'new-branch', both of which are synced with the remote.
git checkout old-branch
# Create a local branch called "new-branch"
# WARNING! Could blow away commits if you added them to to an existing local branch called "new-branch"
git switch -C new-branch
# Set the branch's HEAD without doing a checkout
git reset --soft origin/new-branch
# Un-stage staged changes
git reset
The repo's working copy of its files will be what they were before we started. Run git status
to see differences.
- If a new file was added to
new-branch
it'll show up asdeleted
. - If a file was removed in
new-branch
, it'll show up as untracked. - If a file was modified, it'll show up as modified.
If you then run:
git checkout .
This will undo all the modifications, and restore all the "deleted" (according to git) files, but importantly will not remove the untracked files. This accomplishes what your original question states.