Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a "git pull --dry-run" option in Git?

Tags:

git

git-pull

Is there such a thing as git pull --dry-run to see how stuff will be merged before it messes up my working tree?

Right now I am doing:

git fetch origin && git merge --no-commit --no-ff 

I did not see anything in the man page for 'git-pull' related to it.

To clarify, I just need it in an Ant script for deployment to see if there are conflicts when doing git pull, then back off exit out of build, fail deployment and leave that directory tree the same it was before git pull.

like image 586
Danila Ladner Avatar asked Jun 20 '13 19:06

Danila Ladner


People also ask

What is dry run in git?

It allows you to create a commit with an empty commit message without using plumbing commands like git-commit-tree[1]. This option determines how the supplied commit message should be cleaned up before committing. The <mode> can be strip , whitespace , verbatim , scissors or default .

Is there a git pull force?

Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force ) allows overwriting local branches.

What is git pull -- FF only?

git pull --ff-only corresponds to git fetch git merge --ff-only origin/master. --ff-only applies the remote changes only if they can be fast-forwarded. From the man: Refuse to merge and exit with a non-zero status unless the current HEAD is already up-to-date or the merge can be resolved as a fast-forward.


2 Answers

I have always relied on the inherent abilities of Git to get me back if a merge fails.

To estimate how the merge might occur, you can start like you did with:

$ git fetch origin branch  # Fetch changes, but don't merge $ git diff HEAD..origin/branch # Diff your current head to the fetched commit  ... personal judgement of potential merge conflicts ...  $ git merge origin/branch # merge with the fetched commit 

If things did not go as planned, look at your reflog and reset back to your desired state:

$ git reflog ... abc987  HEAD@{0}: merge activity b58aae8 HEAD@{1}: fetch origin/branch 8f3a362 HEAD@{2}: activity before the fetch ... $ git reset --hard HEAD{2} 
like image 102
rynmrtn Avatar answered Sep 22 '22 19:09

rynmrtn


You will need to fetch first to update your local origin/master

git fetch origin 

Then you can do:

git diff --name-only origin/master 

Will list the files that have changed.

git diff origin/master directory_foo/file_bar.m 

Will list the line by line diff of file directory_foo/file_bar.m.

like image 21
GayleDDS Avatar answered Sep 21 '22 19:09

GayleDDS