1
  • 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 fetch,git merge流程中遗漏了一些东西。

4

1 回答 1

3

git status用于显示工作目录中的内容。所以在 a 之后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 mergeor的简写git fetch; git rebase,具体取决于您的设置。

于 2012-02-11T18:44:32.140 回答