dx_over_dt
dx_over_dt

Reputation: 14318

In Git is it possible to treat my uncommitted changes as merge conflicts?

I made some changes to a file (uncommitted), and want to revert some changes, but not others. VSCode provides a very nice set of buttons for resolving merge conflicts, which would be much more efficient than pulling up the diff of the file and copying over the bits I want to keep. Is there a way to treat a diff file or an applied stash of a file as a set of merge conflicts with HEAD?

git stash -- path/to/my/file
git stash apply
git stash apply

This obviously won't work because the changes to my file are identical to the changes being applied, which presents no merge conflicts.

Upvotes: 1

Views: 231

Answers (1)

Prathap Reddy
Prathap Reddy

Reputation: 1739

This might be round about way of doing it.

  • Checkout a new temp branch from current branch.
  • Commit all your changes.
  • Pull the code from origin to temp brach.
  • All the merge conflicts will show up in VS code now.
  • Add/Remove changes what you need.
  • Commit the final version to the same temp branch.
  • Switch to the original branch again.
  • Do squash merge of temp branch to original branch (git merge --squash temp)
  • Unstage the changes.

Finally, you will end up what you want.

Instead of going through all these steps, you can use VS Code or built-in git gui tool(gitk) for comparison.

Upvotes: 2

Related Questions