title | tags | ||||
---|---|---|---|---|---|
How to do a "dry run" of a git merge to see what would happen without actually committing to it. |
|
Example: You have a local project, and you're on the local branch called dev
. You haven't started working yet, but there may have been other activity since you originally cloned the remote dev
branch, and you want to see how your branch compares to the remote dev
branch so you can get in sync before starting to code - but you don't want to just git pull
and risk conflicts, or losing info.
git s
On branch dev
Your branch is up to date with 'origin/dev'.
- Your on the
dev
branch - Your local project has no information that anything has changed.
git fetch origin dev
# git diff <your-branch> <remote-branch>
git diff `dev` `origin/dev`
git merge --no-commit --no-ff origin/dev
Automatic merge went well; stopped before committing as requested
git s
On branch dev
Your branch is behind 'origin/dev' by 5 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Changes to be committed:
new file: content/_pages/test.md
modified: nuxt.config.ts
modified: package.json
new file: pages/[...slug].vue
modified: pnpm-lock.yaml
You can see there are some changes merged in (but not committed, so you can always go back easily)...
cmd+click
the files to see them, for example the new file: content/_pages/test.md
:
You like what you see... and want to get in sync with the remote.
git merge --abort
# git pull origin <branch>
git pull