git:从其他分支merge个别文件到当前分支, git clone 指定 目录

情形:

我有一个新的分支A,想将A中的部分脚本文件,合并到master上。

使用git merge命令进行分支合并是比较常用的方法,但是会将两个分支的内容完全合并,而我只想合并一个文件。

如果想要和合并一个文件下的多个文件,怎么操作?

操作:

1.切换到master分支。

2.git checkout 分支A 文件名字

(pytorch) localhost:ch wang$ git branch
* master
(pytorch) localhost:ch wang$ git checkout A demo.py # 在ch这个文件夹下面,同步分支A的文件demo.py
(pytorch) localhost:ch wang$ git checkout A demo.py demo2.py #同步多个文件
(pytorch) localhost:ch wang$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   ch/demo.py

#如果你合并文件时,不加分支名字,会报错:
(pytorch) localhost:bert wang$ git checkout demo.py
error: pathspec 'demo.py' did not match any file(s) known to git
#然后提交合并到远程master上
(pytorch) localhost:bert wang$ git add demo.py
(pytorch) localhost:bert wang$ git commit -m 'test'
[master 378352d] test
 1 file changed, 11 insertions(+)
(pytorch) localhost:bert wang$ git push

注:使用git checkout 某个文件到当前分支时,会当前分支的文件强行覆盖。

git checkout  test.py:表示忽略test.py文件的修改,此时代码是未修改状态。

想要合并一个文件下的多个文件到master上,怎么操作?

1.切到master

2.进入到该文件夹下

3.git checkout A test.py  test2.py 

4.git status看看有没有合并到master上。 

git clone 指定 目录

git clone xxx.git “指定目录”

eg:

git clone https://github.com/PearlW1/Chinese-BERT-wwm.git /Users/wang/chinese_copy

此时这个Chinese-BERT-wwm.git项目就在目录:/Users/wang目录下,项目名字是chinese_copy。

这么做有另外一个好处,比如,我想同时打开一个项目的两个分支,对照代码对一些操作,此时可以重新clone一份代码。

git命令查看本地代码的远程仓库

$ git remote -v

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值