能否在 Git 中使用本地计算机上已有的现有文件创建新文件
Can a new file be created in Git with an existing file already on local machine
我可以使用 echo 命令在 Git 中创建一个新文件:echo > newFile.txt
创建文件后,我通常只是从文件资源管理器导航到文件目录,用我的代码更新它并保存它。没问题。
问题是:如果我在本地计算机的工作区中已经有一个包含我所有代码的文件,有没有办法告诉 Git 使用现有文件而不是手动创建一个新文件要编辑新的 Git 文件吗?我想也许可以指定现有的文件路径,以便 Git 可以去获取它?
运行 git init
从文件所在的目录。这会为您的代码创建一个存储库。
然后您可以 git add
和 git commit
您的文件。
然后,添加指向 BitBucket 的 origin
,以便您可以推送代码。
git remote add origin git@bitbucket/path/bitbucket/gives/you/for/your/repo
git push -u origin master
将第一次在远程创建 master 分支。
Git不是关于备份文件的。这是关于维护 files/source 的版本控制。首先,您需要拥有 git 存储库。好像您已经在文件夹中有了源代码。参考:https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ to see how you can add it to GitHub (or any other Git repository you prefer). And now when you have the new file inside this folder do a git status
. It should show if the file exists and if it is being tracked. Please follow : http://media.pragprog.com/titles/tsgit/chap-005-extract.html 了解更多信息。然后你可以继续 add
文件,commit
和 push
。
我可以使用 echo 命令在 Git 中创建一个新文件:echo > newFile.txt
创建文件后,我通常只是从文件资源管理器导航到文件目录,用我的代码更新它并保存它。没问题。
问题是:如果我在本地计算机的工作区中已经有一个包含我所有代码的文件,有没有办法告诉 Git 使用现有文件而不是手动创建一个新文件要编辑新的 Git 文件吗?我想也许可以指定现有的文件路径,以便 Git 可以去获取它?
运行 git init
从文件所在的目录。这会为您的代码创建一个存储库。
然后您可以 git add
和 git commit
您的文件。
然后,添加指向 BitBucket 的 origin
,以便您可以推送代码。
git remote add origin git@bitbucket/path/bitbucket/gives/you/for/your/repo
git push -u origin master
将第一次在远程创建 master 分支。
Git不是关于备份文件的。这是关于维护 files/source 的版本控制。首先,您需要拥有 git 存储库。好像您已经在文件夹中有了源代码。参考:https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ to see how you can add it to GitHub (or any other Git repository you prefer). And now when you have the new file inside this folder do a git status
. It should show if the file exists and if it is being tracked. Please follow : http://media.pragprog.com/titles/tsgit/chap-005-extract.html 了解更多信息。然后你可以继续 add
文件,commit
和 push
。