web-dev-qa-db-ja.com

Gitのサーバーリポジトリから単一のファイルを取得する方法

私はGitを実行しているサーバーのあるサイトに取り組んでいます。私はGitをデプロイに使用しています(GitHubではありません)。これは私が関与する前に hook method を使って設定されていて、 この質問 を参照して以下のコマンドを入力しましたが、うまくいきませんでした。

サーバーから単一のファイルを取得する方法たとえば、ローカルファイルindex.phpを更新したい場合はどうすればいいですか? git pull index.php

80
vsvs

(デプロイされたリポジトリで)実行することは可能です:

git fetch
// git fetch will download all the recent changes, but it will not put it in your current checked out code (working area).

に続く:

git checkout Origin/master -- path/to/file
// git checkout <local repo name (default is Origin)>/<branch name> -- path/to/file will checkout the particular file from the downloaded changes (Origin/master).
138
chrismillah
git fetch --all
git checkout Origin/master -- <your_file_path>
git add <your_file_path>
git commit -m "<your_file_name> updated"

これはOrigin/masterからファイルを引っ張っていると仮定しています。

16
OYORF

これは解決策である場合もあります:

git fetch

git checkout Origin/master -- FolderPathName/fileName

ありがとう。

7

このシナリオは、あなたが-またはあなたよりも大きな力で-ローカルレポジトリ内のファイルをmangledし、新しいコピーを復元したい場合に発生しますリポジトリからの最新バージョンの。/bin/rm(git rmではない)でファイルを削除するか、名前を変更して非表示にしてからgit pullを発行しても機能しません:gitはファイルが存在しないことに気付き、おそらくリポジトリから削除したいことを前提としています(git diffは削除されたすべての行を表示します不足しているファイルから)。

git pullは、他のバージョン管理システムの影響を受けているため(たとえば svn update 信じるwill )ローカルで非表示にされたファイルを復元します)。

git reset --hard HEADは、コミットされていない変更を破棄するため、目的のファイルを復元する代替方法です。ただし、 here で説明したように、気になる他のコミットされていない変更がある場合、git resetは潜在的に危険なコマンドです。

上記の@chrismillahが指摘したgit fetch ... git checkout戦略は、問題のファイルを復元するニースの外科的方法です。

2
Trutane

試してみてください。

git checkout branchName -- fileName

例:

git checkout master -- index.php
0
Dodda Venkata

このWindowsバッチは、GitHub上にあるかどうかに関係なく機能します。いくつかの厳しい警告を示しているため、私はそれを使用しています。 操作が遅く、数百メガバイトのデータを横断していることに気付くでしょう。要件が利用可能な帯域幅に基づいている場合は、この方法を使用しないでください。/RWメモリ。

sparse_checkout.bat

pushd "%~dp0"
if not exist .\ms-server-essentials-docs mkdir .\ms-server-essentials-docs
pushd .\ms-server-essentials-docs
git init
git remote add Origin -f https://github.com/MicrosoftDocs/windowsserverdocs.git
git config core.sparseCheckout true
(echo EssentialsDocs)>>.git\info\sparse-checkout
git pull Origin master

=>

C:\ Users\user name\Desktop> sparse_checkout.bat

C:\ Users \ユーザー名\ Desktop> pushd "C:\ Users \ユーザー名\ Desktop \"

C:\ Users\user name\Desktop>存在しない場合。\ ms-server-essentials-docs mkdir。\ ms-server-essentials-docs

C:\ Users\user name\Desktop> pushd。\ ms-server-essentials-docs

C:\ Users\user name\Desktop\ms-server-essentials-docs> git init C:/ Users/user name/Desktop/ms-server-essentials-docs/.git /の初期化された空のGitリポジトリ

C:\ Users\user name\Desktop\ms-server-essentials-docs> git remote add Origin -f https://github.com/MicrosoftDocs/windowsserverdocs.git Originリモートの更新:オブジェクトの列挙:97、完了。リモート:オブジェクトのカウント:100%(97/97)、完了。 remote:オブジェクトの圧縮:100%(44/44)、完了。リモート:合計145517(デルタ63)、再利用76(デルタ53)、パック再利用145420受信オブジェクト:100%(145517/145517)、751.33 MiB | 32.06 MiB/s、完了。デルタの解決:100%(102110/102110)、完了。 https://github.com/MicrosoftDocs/windowsserverdocs * [新しいブランチ]
1106-conflict-> Origin/1106-conflict * [新しいブランチ]
FromPrivateRepo-> Origin/FromPrivateRepo * [新しいブランチ]
PR183-> Origin/PR183 * [新しいブランチ]
conflictfix-> Origin/conflictfix * [新しいブランチ]
eross-msft-patch-1-> Origin/eross-msft-patch-1 * [新しいブランチ]
master-> Origin/master * [新しいブランチ] patch-1
-> Origin/patch-1 * [新しいブランチ] repo_sync_working_branch-> Origin/repo_sync_working_branch * [新しいブランチ]
shortpatti-patch-1-> Origin/shortpatti-patch-1 * [新しいブランチ]
shortpatti-patch-2-> Origin/shortpatti-patch-2 * [新しいブランチ]
shortpatti-patch-3-> Origin/shortpatti-patch-3 * [新しいブランチ]
shortpatti-patch-4-> Origin/shortpatti-patch-4 * [新しいブランチ]
shortpatti-patch-5-> Origin/shortpatti-patch-5 * [新しいブランチ]
shortpatti-patch-6-> Origin/shortpatti-patch-6 * [新しいブランチ]
shortpatti-patch-7-> Origin/shortpatti-patch-7 * [新しいブランチ]
shortpatti-patch-8-> Origin/shortpatti-patch-8

C:\ Users\user name\Desktop\ms-server-essentials-docs> git config core.sparseCheckout true

C:\ Users\user name\Desktop\ms-server-essentials-docs>(echo EssentialsDocs)1 >>。git\info\sparse-checkout

C:\ Users\user name\Desktop\ms-server-essentials-docs> git pull Origin master
From https://github.com/MicrosoftDocs/windowsserverdocs
*ブランチマスター-> FETCH_HEAD

0
https://raw.githubusercontent.com/[USER-NAME]/[REPOSITORY-NAME]/[BRANCH-NAME]/[FILE-PATH]

https://raw.githubusercontent.com/vipinbihari/apana-result/master/index.php

これにより、個々のファイルの内容を行テキストとして取得できます。あなたはそのテキストをwgetでダウンロードすることができます。

https://raw.githubusercontent.com/vipinbihari/apana-result/master/index.php

0