在git bash中创建一个新文件 [英] Create a new file in git bash

查看:594
本文介绍了在git bash中创建一个新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Git for Windows正在运行,我不确定它是否应该用作文本编辑器?



我想我已经安装了它Vim编辑器,但在Git Bash shell中,我如何创建一个文件,比如webpage.html?

  $ git添加网页.html 

返回为

  fatal:pathspec'webpage.html'与任何文件不匹配

因为它试图跟踪一个不存在的文件。



我知道我可以在github.com界面上创建一个新文件,这很容易,我想知道是否我可以创建一个新文件(如cmd中的echo)以及该文件是否实际上是空白的( echo in cmd创建非空白文件)以及如何从git bash shell写入该文件?



如果没有,我猜我应该创建一个新文件Windows资源管理器?这是常态...?



编辑



哇,我是当我问上述情况时,所有这些都是新的。不,Git Bash不是文本编辑器,它是Unix上的 git 工具的Windows版本,只处理文件版本控制。 git add git rm 和其他 git 命令处理版本控制文件管理器如何处理文件和文件夹,结果是它改变的唯一的东西是在名为 .git 的隐藏文件夹中。



当时我很困惑,因为顾名思义,Git Bash带有bash shell命令,而不仅仅是 git - 例如 ls (列表文件), mkdir (制作新文件夹),以及 - 我正在寻找 - touch (在现有文件上创建一个新文件或更新时间戳), echo (打印文本到命令行,或者将该文本指向文件)。



我可以用>创建我的新文件 webpage.html $ b

  touch webpage.html 

然后写入它与:

  echo<!DOCTYPE html> > webpage.html 

然后附上以下内容:

  echo< html>> webpage.html 
回显< head> >> webpage.html

等等 - 但我不认为有任何文本编辑器(根据< a href =http://www.codeproject.com/Articles/457305/Basic-Git-Command-Line-Reference-for-Windows-Users =noreferrer>这个命令列表)。请参阅此主题了解如何在Windows上设置Git的文本编辑器。

/ strong> shell,您可以使用以下技巧:

 > webpage.html 

这实际上是一样的:

  echo> webpage.html 

然后,您可以使用 git add webpage.html code>来存档文件。


I've got Git for Windows running, I'm not sure if it's supposed to function as a text editor though?

I think I installed it with the Vim editor, but in a Git Bash shell how do I create a file, such as webpage.html?

$ git add webpage.html

comes back as

fatal: pathspec 'webpage.html' did not match any files

because it tries to track a non-existing file.

I understand I can create a new file on the github.com interface, that's easy enough, I'm wondering if I can create a new file (like echo in cmd) and whether this file will actually be blank (echo in cmd creates non-blank files) and how I can write into that file from the git bash shell?

If not, I'm guessing I should just create a new file in windows explorer? Is that the norm...?

Edit

Wow, I was new to all this when I asked the above. No, Git Bash isn't a text editor, it's a Windows version of the git facility on Unix, and only handles the file versioning. git add, git rm, and other git commands just handle how the version control file manager handles the files and folders, and the only things it changes as a result are in a hidden folder named .git. Sorry if this has confused anyone.

I was confused at the time because, as the name suggests, Git Bash has bash shell commands shipped with it, not just git - e.g. ls (list files), mkdir (make new folder), and -- what I was looking for -- touch (make a new file or update timestamp on existing file), and echo (print text to the command line, or direct that text to a file).

I could have made my new file webpage.html with:

touch webpage.html

Then written to it with:

echo "<!DOCTYPE html>" > webpage.html

Then appended lines to it with:

echo "<html" >> webpage.html
echo "<head>" >> webpage.html

and so on - but I don't think there's any text editor (according to this list of commands). See this thread for details of setting up a text editor with Git on Windows.

解决方案

If you are using the Git Bash shell, you can use the following trick:

> webpage.html

This is actually the same as:

echo "" > webpage.html

Then, you can use git add webpage.html to stage the file.

这篇关于在git bash中创建一个新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆