简体   繁体   English

Git是否可以在存储库中的特定文件夹中提交文件?

[英]Is it possible with Git to commit a file in a specific folder in the repository?

I'm new with git and I'm trying to use JGit in a java application. 我是git的新手,正在尝试在Java应用程序中使用JGit。 I would like to know if Git has a 'commmit of files into a specific directory' or is Git only based on the working tree where files are stored? 我想知道Git是否具有“将文件提交到特定目录中”或Git仅基于存储文件的工作树吗?

For example, let's say I have a file saved in C:/tmp/myfile.docx. 例如,假设我有一个文件保存在C:/tmp/myfile.docx中。 Is it possible to tell Git to store it in the repository as /myProject/myfile.docx ? 是否可以告诉Git将其作为/myProject/myfile.docx存储在存储库中?

Thank you :) 谢谢 :)

That is not possible. 这是不可能的。 Think of your Git repository as a time machine for a tree of directories. 将您的Git存储库想像成目录树的时间机器。 You can only add files to git that are inside that directory tree. 您只能将该目录树中的文件添加到git中。 And don't try to make C:\\ a Git repository... :) 而且不要尝试使C:\\一个Git存储库... :)

So, let's say your Git repository resides at C:\\tmp\\myRepo . 因此,假设您的Git存储库位于C:\\tmp\\myRepo To add your file to the repository you'd do this: 要将文件添加到存储库,请执行以下操作:

  1. move myfile.docx to C:\\tmp\\myRepo myfile.docx移至C:\\tmp\\myRepo
  2. add the file to Git: (using Unix style command line) cd C:/tmp/myRepo && git add -A 将文件添加到Git :(使用Unix样式的命令行) cd C:/tmp/myRepo && git add -A
  3. create a commit: git commit -am "added myfile.docx" 创建一个提交: git commit -am "added myfile.docx"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将文件从 web 应用程序(弹簧启动)提交到 git 远程存储库,而不首先将存储库克隆为本地? 这可能吗 - commit file from a web application (spring boot) into git remote repository without first cloning the repo as local? is this possible Git存储库分支可以是其他一些Git存储库中的子文件夹吗? - Can a Git Repository Branch be a sub folder in some other Git Repository? 有没有办法用 Maven 将 git 存储库签出到某个文件夹? - Is there a way to checkout git repository, to certain folder with maven? 是否可以使用 JGit 的内存存储库将一个小文件添加到一个大 Git 存储库,而无需在本地进行检查? - Is it possible to use JGit's in-memory repository to add one small file to a big Git repository without checking it out locally? 如何在不添加Remote的情况下将提交推送到git存储库? - How to push commit to git repository without adding Remote? 使用JGit按分支或提交ID签出Git存储库 - Checking out a Git repository by branch or commit ID using JGit 是否可以只使用 git 存储库的一部分? - is possible to work only with a part of a git repository? 如何使用Java中的stash rest API获取stash存储库中特定文件夹内的文件名列表 - How to get list of file names inside a specific folder in stash repository using stash rest API in Java 读取任何项目的Git提交日志文件 - reading Git Commit Log file for any project Git没有在Eclipse中提交文件 - Git doesn't commit a file in eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM