0

This is probably a generic git question, but I mention Gerrit in case there's a specific workflow that achieves this.

A colleague has pointed me to a private changeset (in the same branch) that contains a few changes that we do not want to merge.

I'd like to apply the changeset locally but I need to keep working in the same branch and pushing changes without pushing the changes applied by this changeset. I think what I'm after is a way to apply the changes and just keep those changes unstaged so that I can do an update-index on them and not accidentally commit them later, but I'm not sure how to accomplish that or if there's a better way.

EDIT: Ok after RTFM some more, I discovered cherry-pick has an option to not commit. This gets me where I want, but I wanted to leave the question open just to see if there's a better way to do this type of workflow.

amnesia
  • 1,956
  • 2
  • 18
  • 36
  • A better way probably not, but with git only you can create a new branch with the merged changeset. From now on you work on this branch but you cherrypick every commit you do inside the master branch (or the one you want to push). maybe you can add a githook (post-commit) to sync the 2 branches every time you commit. – Marco Luzzara Jan 27 '21 at 21:54

1 Answers1

0

In many cases with git, creating a new branch is the right option!
If you can create a new branch and work there instead, do so!

git checkout -b mynewbranch
git cherry-pick ...

If you have some need to actively develop both changesets in a way which prevents you from creating a new branch,

  • question it somewhat strongly
  • check out the repository twice (different filesystem paths) and merge only in one instance of it

To prevent errors, you can remove the remote from one instance (git remote -v to show), effectively preventing push to the shared repo

ti7
  • 16,375
  • 6
  • 40
  • 68