簡體   English   中英

Git按日期簽出在Windows上顯示錯誤

[英]Git checkout by date gives error on Windows

我想從git簽出並使用此SO-link中的命令。 我不確定我在做什么錯。

我試過以下命令。

git checkout `git rev-list -n 1 --before="2015-3-3 13:37:00" master`
git checkout `git rev-list 1 --before="2015-3-3 13:37:00" master`
git checkout `git rev-list -1 --before="2015-3-3 13:37:00" master`

並得到以下錯誤。

C:\Users\junaid\Documents\GitHub\bucardo [master]> git checkout `git rev-list -n 1 --before="2015-3-3 13:37:00" master`
error: unknown switch `n'
usage: git checkout [options] <branch>
   or: git checkout [options] [<branch>] -- <file>...

    -q, --quiet           suppress progress reporting
    -b <branch>           create and checkout a new branch
    -B <branch>           create/reset and checkout a branch
    -l                    create reflog for new branch
    --detach              detach the HEAD at named commit
    -t, --track           set upstream info for new branch
    --orphan <new branch>
                          new unparented branch
    -2, --ours            checkout our version for unmerged files
    -3, --theirs          checkout their version for unmerged files
    -f, --force           force checkout (throw away local modifications)
    -m, --merge           perform a 3-way merge with the new branch
    --overwrite-ignore    update ignored files (default)
    --conflict <style>    conflict style (merge or diff3)
    -p, --patch           select hunks interactively
    --ignore-skip-worktree-bits
                          do not limit pathspecs to sparse entries only

但是遵循以下命令是可行的,但我認為它只能追溯到90天。

C:\Users\junaid\Documents\GitHub\bucardo [master]> git checkout 'master@{2015-3-27 18:30:00}'
warning: Log for 'master' only goes back to Thu, 17 Mar 2015 18:08:03 -0500.
Note: checking out 'master@{2015-07-27 18:30:00}'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at cb4f95a... Start the cleanup of delete_rows()
C:\Users\junaid\Documents\GitHub\bucardo [(cb4f95a...)]>

在Bash(以及許多其他Unixy shell)中,反引號用於命令替換 ,例如,請參見Linux文檔項目中的以下描述

命令替換允許命令的輸出替換命令本身。 如下所示封閉命令時,將發生命令替換:

 $(command) 

或使用反引號這樣:

 `command` 

Bash通過執行COMMAND並用命令的標准輸出替換命令替換來執行擴展,並刪除所有尾隨的換行符。 嵌入的換行符不會被刪除,但是可以在分詞時將其刪除。

 franky ~> echo `date` Thu Feb 6 10:06:20 CET 2003 

我認為cmd.exe根本不支持真正的命令替換。 它肯定不會這樣處理反向引號。

您可以嘗試一些解決方法,例如for /f臨時文件 ,但是使用起來很尷尬。

根據您安裝Git的方式,您可能可以訪問Windows上應以所需方式運行的Bash shell

如果您可以訪問PowerShell, $(...)語法應該可以正常工作 ,Bash也支持該語法 posh-git作為PowerShell上Git的環境而享有盛譽,盡管我從未親自使用過。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM