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

后端 未结 7 1344
星月不相逢
星月不相逢 2021-01-29 22:43

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 f         


        
相关标签:
7条回答
  • 2021-01-29 23:20

    Since pulling implies merging, I'd go with running git merge --abort if your script detects there were any conflicts and merging failed.

    0 讨论(0)
  • 2021-01-29 23:21

    Since v2.27.0 there is a dry-run flag

    0 讨论(0)
  • 2021-01-29 23:29

    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}
    
    0 讨论(0)
  • 2021-01-29 23:32

    See my answer in this similar question:

    How to preview git-pull without doing fetch?

    this goes to the ~/.gitconfig file:

    [alias]
            diffpull=!git fetch && git diff HEAD..@{u}
    
    0 讨论(0)
  • 2021-01-29 23:33

    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.

    0 讨论(0)
  • 2021-01-29 23:36

    You can get the effect you want by creating a new throw-away branch from your current one and doing the git pull there. If you're unhappy with the results, the original branch is intact.

    0 讨论(0)
提交回复
热议问题