[Git] Combinar un solo archivo en otra rama a la rama actual

Directorio de artículos

  • Cambie el archivo a fusionar (agregue un comentario inútil o algo así) y Ctrl + Sguárdelo, luego verifique la ruta del archivo y cópielo
➜  csdn git:(test) git status
On branch test
Your branch is ahead of 'origin/test' by 1 commit.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   src/pages/components/modal.tsx

no changes added to commit (use "git add" and/or "git commit -a")
# src/pages/components/modal.tsx 就是我们要的文件路径
  • Después de copiar la ruta del archivo, descarte los cambios inútiles
# 该命令会回退工作区的所有改动
➜  csdn git:(test) git checkout -- .
➜  csdn git:(test) git status
On branch test
Your branch is ahead of 'origin/test' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
  • Luego cambie a la rama actual ( dev):
➜  csdn git:(test) git checkout dev 
➜  csdn git:(dev)
  • Por ejemplo, si testdesea modal.tsxfusionar los archivos de la rama en devla rama , puede hacer esto:
➜  csdn git:(dev) git checkout --patch test src/pages/components/modal.tsx
# 这里选择处理方式:将此块应用于索引和工作树(输入 `y` ,按回车)
(1/3) Apply this hunk to index and worktree [y,n,q,a,d,j,J,g,/,s,e,?]? 	y
(2/3) Apply this hunk to index and worktree [y,n,q,a,d,j,J,g,/,s,e,?]? 	y
(3/3) Apply this hunk to index and worktree [y,n,q,a,d,j,J,g,/,s,e,?]? 	y
  • analizar
y - 存储这个hunk 
n - 不存储这个hunk 
q - 离开,不存储这个hunk和其他hunk 
a - 存储这个hunk和这个文件后面的hunk 
d - 不存储这个hunk和这个文件后面的hunk 
g - 选择一个hunk 
/ - 通过正则查找hunk 
j - 不确定是否存储这个hunk,看下一个不确定的hunk 
J - 不确定是否存储这个hunk,看下一个hunk 
k - 不确定是否存储这个hunk,看上一个不确定的hunk 
K -不确定是否存储这个hunk,看上一个hunk 
s - 把当前的hunk分成更小的hunks 
e - 手动编辑当前的hunk 
? - 输出帮助信息

Supongo que te gusta

Origin blog.csdn.net/qq_45677671/article/details/131053628
Recomendado
Clasificación