【问题标题】:How can git-fetch only download changes without adding/updating files?git-fetch 如何只下载更改而不添加/更新文件?
【发布时间】:2012-03-03 14:49:09
【问题描述】:
  • Project.git 是一个远程 git 仓库,有一个暂存分支
  • 两个开发人员正在开发他们自己的 project.git 分支
  • 两个开发人员都只与登台交互

两个开发者共同

# Developer 1 & developer 2 add staging as follows
$ git clone myForkOfProject.git
$ git remote add live project.git

开发人员 2 处理文档

[master] $ git branch docs
[master] $ git checkout docs
[docs] $ git add README 
[docs] $ git commit -m "pushing to live's staging from local's docs works" README
[docs] $ git push live docs:staging

开发人员 1 正在修复错误,希望有选择地合并文档

开发者 1 希望看到选择性地将文档中的文件合并到他的本地 mybranch

[master] git branch mybranch
[master] git checkout mybranch
[mybranch] $  git fetch live staging

# Checks to see if anything changed
[mybranch] $  git status -s ./
[mybranch] $

# Doesn't know what to merge since diff, status shows no change 

# Where as if developer1 did
[mybranch] $  git pull live staging
[mybranch] $  git status -s ./
A  README

developer1 真正想要的是什么

developer1 想要做的只是将 staging 中的最后更改提取到工作目录中,而不自动添加 README。

如何拉取/获取以便git status -s ./ 只下载更改

[mybranch] git *fetch changes from staging into mybranch 's working directory*
[mybranch] git status -s ./
[?] README
# This is what developer1 wants to see
# so that he can decide to 'git add README' manually
# here are the unsuccessful attempts to do the same

# Developer2 makes a commit, and does git push live docs:staging 
[mybranch] $ git fetch live staging
[mybranch] $ git pull live staging --no-commit --no-log --no-ff

我的最后一个选项是选择性地调用git rm --cached README,但我想知道我是否在git fetchgit merge 流程中遗漏了什么。

【问题讨论】:

    标签: git git-pull git-fetch


    【解决方案1】:

    git status 用于显示工作目录中的内容。所以在git fetch 之后,它不会改变工作副本,当然你什么也看不到。

    git show 用于显示变更集。因此,如果您想在应用之前查看更改,请执行git show(使用git log live..mybranch 或类似方法查找要检查的更改;您甚至可以使用git log --patch 来查看与提交注释内联的差异)。

    但是,在此工作流程中,您说您特别希望将更改合并到工作副本中 - 但提交它们。

    您可以分两步执行此操作:首先,您git merge 与您的更改一起。然后,你 git reset [revision],给出你在合并之前的修订。

    这将使您没有分阶段的更改,一个未移动的HEAD(您重置回合并之前的状态,因此它已被有效地反转),以及一个包含您执行git merge之前的所有修改的工作副本.

    git pull 只是git fetch; git mergegit fetch; git rebase 的简写,具体取决于您的设置。

    【讨论】:

    • 我认为git merge 后跟git reset 会更好地使用git merge --squash(可能后跟git reset <paths> 取消暂存),这样可以避免做和撤消的事情。此外,“您在合并之前的修订版”可以通过@{1} 或(在简单的情况下)HEAD@{1} 自动获得。
    • 感谢 Borealid 和凯文。将使用 git fetch,然后使用 git show 和 git log 进行预览,然后使用 git merge 最终将 git reset 设置为 unstage
    猜你喜欢
    • 2017-03-12
    • 2014-10-12
    • 1970-01-01
    • 2013-03-23
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 1970-01-01
    • 2013-05-13
    相关资源
    最近更新 更多