magit 如何实现将当前分支的某个文件替换为其他分支的文件?



git checkout – path

path 就是你想要替换的目录或文件

b b (magit-checkout)

Checkout a revision read in the minibuffer and defaulting to the branch or arbitrary revision at point. If the revision is a local branch then that becomes the current branch. If it is something else then HEAD becomes detached. Checkout fails if the working tree or the staging area contain changes.

b c (magit-branch-and-checkout)

This command creates a new branch like magit-branch-create, but then also checks it out.

Also see option magit-branch-prefer-remote-upstream.

b l (magit-branch-checkout)

This command checks out an existing or new local branch. It reads a branch name from the user offering all local branches and a subset of remote branches as candidates. Remote branches for which a local branch by the same name exists are omitted from the list of candidates. The user can also enter a completely new branch name.

  • If the user selects an existing local branch, then that is checked out.
  • If the user selects a remote branch, then it creates and checks out a new local branch with the same name, and configures the selected remote branch as the push target.
  • If the user enters a new branch name, then it creates and checks that out, after also reading the starting-point from the user.

In the latter two cases the upstream is also set. Whether it is set to the chosen starting point or something else depends on the value of magit-branch-adjust-remote-upstream-alist.