When committing go code to a gitlab project, splitting the vendor dependencies, makes sense to reduce the browser changes tab render. So here is a quick way to commit one code commit and one vendor. I will use AWK to separate the code from vendor files and create two commits.
First I go to the master commit, my other commits are on top of this commit.
git reset --soft master
Magic:
git commit $(git status |awk '/^[\t]{1}.*:/ {if (index($NF, "vendor") == 0 && $NF != "go.mod" && $NF != "go.sum") {printf "%s ", $NF}}') -m 'feature code'
git status
- show all the files changed since the master commit
/^[\t]{1}}.*:/
- filter from status the tracked changed files, in fact they start with five spaces
if (index($NF, "vendor") == 0 && $NF != "go.mod" && $NF != "go.sum")
- filter out vendor files and the go.mod and go.sum files.
{printf "%s ", $NF}
- print files in sequence without new lines
Now commit the vendor files:
git commit go.mod go.sum vendor/* -m 'vendor files'
Before pushing use:
git diff HEAD^ HEAD^^ --name-only
to verify the committed files