Git pull just one commit

后端 未结 2 1025
悲&欢浪女
悲&欢浪女 2021-02-15 05:56

Actually the git repository and local files are exactly the same.

But the other website is far away from 5 commits, so I haven\'t pull in a while and I don\'t want to do

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-15 06:38

    git pull is essentially a shorthand for git fetch (download remote commits into remote-tracking branches) and then git merge (merge your HEAD, i.e. the current commit, with the ones you just downloaded).

    You can get the flexibility you expect by decoupling both steps:

    • First, run git fetch, then inspect the history you just downloaded (if you work on the master branch, git fetch should have downloaded remote commits in branch origin/master which you can inspect with git log origin/master).

    • Then, merge the commit you want using git merge . Note: git merge will get all the changes in and its ancestry, so this works if is the oldest non-merged commit. If you do not have any unpushed commits, this will "fast-forward", i.e. it won't create a new commit but just advance HEAD to this commit. If you're not happy with git merge, you have other options like git rebase, git cherry-pick, ...

提交回复
热议问题