- 我在本地修改单个文件并运行
git add
、git commit
和git push
- 该文件被推送到远程源主库存储库
- 我有另一个使用"remote_cache"方法从该远程存储库部署的本地存储库
- 现在我不想部署整个应用程序,只想更新/检出该单个文件。
svn up file
即可。
git add
、git commit
和git push
svn up file
即可。
可以在部署的代码库中完成此操作。
git fetch
git checkout origin/master -- path/to/file
fetch会下载所有最近的更改,但不会将其放入您当前检出的代码(工作区)。
checkout会使用从下载的更改(origin/master
)中特定的文件更新工作树。
对于我来说,至少在进行那些小的错别字修复时很有效,这样做只为了更改文件中的一个单词感觉有些奇怪。
错误:路径规范'upstream/master'未与git知道的任何文件匹配
致命错误:只期望一个引用,但给出了2个
。 - Alex Barkergit checkout origin/master -- path/to/folder/*
(注意最后的*)。 - mcouthon随着Git 2.23(2019年8月)和新的(仍处于实验阶段)命令git restore
的出现,可以看到在 "How to reset all files from working directory but not from staging area?" 中:
git fetch
git restore -s origin/master -- path/to/file
git restore
只处理文件,而不像git checkout
那样处理文件和分支。git checkout
":这就是git switch
的用处。
codersam在评论中添加了in the comments:
in my case I wanted to get the data from my upstream (from which I forked).
So just changed to:git restore -s upstream/master -- path/to/file
git restore -s upstream/master -- path/to/file
。 - coderSamrestore
更好,因为它将文件放在工作区而不是暂存区,而 checkout
则会将文件放在暂存区。 - Zac以下代码对我有效:
git fetch
git checkout <branch from which file needs to be fetched> <filepath>
git fetch <remote>; git checkout <remote>/<branch> -- <file>
- Hashbrown对我来说,它很简单实用。
git checkout origin/develop file_name.php
--
。
git checkout origin/develop -- file_name.php
- Franckgit archive --format=zip --remote=ssh://<user>@<host>/repos/<repo name> <tag or HEAD> <filename> > <output file name>.zip
git archive --remote=https://github.com/git/git.git master:git/contrib/completion git-completion.bash | tar -x
给我一个错误消息:fatal: Operation not supported by protocol.
- Alderathtar
的 --to-stdout
,git archive --remote="gitolite3@<host>:<repo>" <tag> <file> | tar xf - --to-stdout
很棒。 - Puggan Se更新本地 git 仓库:
git fetch
在本地创建分支并切换到它:
git branch pouet && git checkout pouet
将需要应用的提交应用到此分支:
git cherry-pick abcdefabcdef
(abcdefabcdef 是你想要应用的提交的 SHA1)
git checkout -b pouet
。 - Greg Hewgillgit checkout master
git pull --rebase
git checkout dev
git checkout master ./app/file.py
如果你有修改,可以使用git stash命令,然后切换到主分支(master),拉取最新的更改,将该文件(或整个应用程序)复制到桌面上。然后再切换回原来的分支,使用git stash apply命令回到之前的状态,手动修复修改或替换文件。
这种方法不是很酷,但如果你们无法找到其他解决方案,它绝对可行。
我想我已经找到了一个简单的解决方法。
删除本地仓库中的文件(即您想要从远程服务器更新的文件)
然后执行 git pull
由于文件被删除,所以不会产生冲突
git restore -s origin/master -- path/to/file
。请参见下面的答案。 - VonC