2010-06-08 60 views
68

mercurial中是否有命令會列出當前在源代碼管理下的所有文件?如何在Mercurial(hg)中列出存儲庫中的所有文件?

我可以做一個dir /s列出我的文件夾和子文件夾中的所有文件,但我不知道哪些已被添加到我的存儲庫。我有各種排除的文件類型和文件夾,我想確認它們都沒有添加,然後在我的.hgignore文件中設置它們。

+0

你應該看看這篇文章:http://mercurial.808500.n3.nabble.com/List-files-in-a-directory-td949176.html#a949176 – Pedro 2010-07-08 08:36:25

回答

68

hg status --all將列出樹中的所有文件,並帶有一個字母指示其狀態:M表示修改,C表示清除(由hg擁有),I表示忽略。

僅限於忽略文件,請使用hg status -i。對於僅在下一次提交時添加的文件,請使用hg status -a。這些僅顯示您需要知道的內容,並且不需要掃描長文件列表。

+2

由於其他人可能會在這裏尋找信息,我想我會提到我的新的hglist擴展,它給了Mercurial一個「ls」命令:http://alastairs-place.net/projects/hglist/ – alastair 2012-12-13 14:32:26

+2

'hg st -A' is上述命令的縮寫版本。 – 2013-06-20 08:53:17

+8

很好的答案,但它並不直接回答問題。在乾淨的工作狀態下,'hg status -c'列出所有跟蹤的文件和只跟蹤的文件。有了其他變化,'hg status -carmd'就可以做到。添加'-n'來排除狀態標誌。 – undefined 2014-03-06 17:26:15

19

hg manifest將僅列出存儲庫中的文件,而hg status --all將列出存儲庫結構中的所有文件並且包括正被跟蹤的標記以及未被跟蹤的標記。

+1

這給了我正是我想要的,儘管它有一點小小的缺點,不能像OP想要的文件夾那樣縮小。它比接受的答案還要好。 – 2014-01-14 16:47:47

-4
 
C:\>hg help -v status 
hg status [OPTION]... [FILE]... 

aliases: st 

show changed files in the working directory 

    Show status of files in the repository. If names are given, only files 
    that match are shown. Files that are clean or ignored or the source of a 
    copy/move operation, are not listed unless -c/--clean, -i/--ignored, 
    -C/--copies or -A/--all are given. Unless options described with "show 
    only ..." are given, the options -mardu are used. 

    Option -q/--quiet hides untracked (unknown and ignored) files unless 
    explicitly requested with -u/--unknown or -i/--ignored. 

    NOTE: status may appear to disagree with diff if permissions have changed 
    or a merge has occurred. The standard diff format does not report 
    permission changes and diff only reports changes relative to one merge 
    parent. 

    If one revision is given, it is used as the base revision. If two 
    revisions are given, the differences between them are shown. The --change 
    option can also be used as a shortcut to list the changed files of a 
    revision from its first parent. 

    The codes used to show the status of files are: 

     M = modified 
     A = added 
     R = removed 
     C = clean 
     ! = missing (deleted by non-hg command, but still tracked) 
     ? = not tracked 
     I = ignored 
     = origin of the previous file listed as A (added) 

options: 

-A --all    show status of all files 
-m --modified  show only modified files 
-a --added   show only added files 
-r --removed   show only removed files 
-d --deleted   show only deleted (but tracked) files 
-c --clean   show only files without changes 
-u --unknown   show only unknown (not tracked) files 
-i --ignored   show only ignored files 
-n --no-status  hide status prefix 
-C --copies   show source of copied files 
-0 --print0   end filenames with NUL, for use with xargs 
    --rev    show difference from revision 
    --change   list the changed files of a revision 
-I --include   include names matching the given patterns 
-X --exclude   exclude names matching the given patterns 

global options: 
-R --repository  repository root directory or name of overlay bundle file 
    --cwd    change working directory 
-y --noninteractive do not prompt, assume 'yes' for any required answers 
-q --quiet   suppress output 
-v --verbose   enable additional output 
    --config   set/override config option (use 'section.name=value') 
    --debug   enable debugging output 
    --debugger  start debugger 
    --encoding  set the charset encoding (default: cp1252) 
    --encodingmode set the charset encoding mode (default: strict) 
    --traceback  always print a traceback on exception 
    --time   time how long the command takes 
    --profile   print command execution profile 
    --version   output version information and exit 
-h --help   display help and exit 
+4

有趣的是,我的答案一年比一年低。但是告訴人們閱讀手冊真的不好嗎? stackoverflow是否使文檔無效?有人停止使用'--help' /'/?'/'man'和其他文檔,因爲在stackoverflow上查詢比在讀取時更快?我拒絕刪除我的回答:) – simendsjo 2014-01-29 07:37:12

+0

呃,好吧,你可以爲我投票,因爲這是最有用的答案。我不會再根據我發現的內容來寫另一個,看看我是否得到任何讚揚:-) – Benjohn 2014-10-09 14:25:05

+1

對於它的價值,你的答案是好的。但是用戶需要知道'status',因爲其中一個'hg'命令實際上會做到這一點。我每天都使用Mercurial,但我不知道它可能會被要求顯示忽略的文件。 – Benjohn 2014-10-09 14:42:29

57

您也可以查看hg locate命令。我將它與-I選項一起使用,當我想將文件限制到某個目錄時。

列出所有文件在你的資料庫:

hg locate 

從存儲庫(「根」)目錄:

hg locate -I dir/sub_dir/dir_of_interest 

傳遞給-I需求的路徑變化取決於目錄中你運行命令。如果您在本例中運行從dir目錄上面的命令,你需要修改你的論點找到:

hg locate -I sub_dir/dir_of_interest 

輸出文件的列表將保持不變,顯示在庫中的每個文件的完整路徑。

嘗試hg help -v locate瞭解更多信息。

+2

正是我需要的,謝謝。對於只需要列出被跟蹤文件的人來說,這是一個更好的答案。 – 2011-02-23 04:52:50

+1

'hg loc'是上述命令的縮寫版本。 – 2013-06-20 08:55:48

+3

這是真正的答案。奈德的回答是非首發。 – 2014-01-14 16:45:29

3

上市僅忽視或添加的文件

列出忽略文件,這樣做:hg status -i

僅僅對於增加了文件,請做hg status -a

如果您不喜歡打字太多,可以將這些縮短爲hg sta -ihg sta -a

status這兩個用途比locate更簡單,並會給你你關心的特定文件狀態,所以它明顯不太容易出錯。

更多hg status

要列出一個善變的回購協議中的所有文件做:hg status --all

的文件將給予他們之前的前綴列,當他們:

M = modified 
    A = added 
    R = removed 
    C = clean 
    ! = missing (deleted by non-hg command, but still tracked) 
    ? = not tracked 
    I = ignored 

如果要列出文件夾在只有文件,可以提供一個路徑:

  • hg st --all MyFolder - MyFolder中的所有文件
  • hg sta -i MyFolder - 僅忽略MyFolder中的文件。

還有-i爲「忽略」和-a爲「增加」,其他標誌都可以只列出具有特定身份的文件。

獲取help

閱讀the other very useful answer herestatus命令的全面解釋。它有向下票,因爲作者試圖表明您可以通過詢問水銀有關status命令這樣發現上述所有的:

hg help status 

你可以問水銀告訴你任何關於它的命令喜歡這個。如果你想要一個Mercurial的命令列表,然後輸入hg help

相關問題