创建新的本地git仓库,使用不同版本的Java项目文件。

huangapple go评论83阅读模式
英文:

Creating new local git repository from different versions of a java project files

问题

  1. 从这些不同命名的根目录中,在git中创建一个本地仓库。
  2. 查看这些版本之间的差异。
英文:

I am new to git, I have many versions of a project stored in my local computer I wish to do the following

  1. create a local repository in git from these versions with differently named root directory
  2. see the differences between the versions

pl. help

答案1

得分: 1

创建一个新目录,以后称为 x,然后 cd x。然后运行 git init。这将在 x 目录内启动一个新的空 Git 存储库。Git 存储库是一个包含 .git 子目录的文件夹。

将项目的第一个版本的文件复制并粘贴到 x 目录内。

x 目录内创建一个 .gitignore 文件,并告诉它哪些项目文件不希望被 Git 跟踪。查看这里以获取更多信息。

完成后,运行 git add -A 命令,告诉 Git 跟踪目录中的所有文件并准备进行提交(这将添加除了 .gitignore 中提到的文件以外的所有文件)。

现在运行 git commit -m "这是我的项目的第一个版本"

现在进行第二个版本 - 完全覆盖 x 目录内的所有文件,使用第二个版本的文件(删除除了 .gitignore.git 以外的所有内容,然后粘贴第二个版本的文件)。然后执行与之前类似的命令:

git add -A

git commit -m "我的项目的第二个版本"

重复这些步骤以处理所有版本 - 覆盖文件,git add,git commit,重复。

现在你有一个本地 Git 存储库,每个提交对应于你的 Java 项目的一个版本。

你可以使用 git diff 命令或者你选择的 Git GUI 工具 来查看版本之间的差异,这些工具允许你浏览你新创建的存储库。

你现在也可以将存储库上传到你选择的 Git 托管服务(常见的有 GithubBitBucketGitLab 等)中,方法是在这些服务中创建一个空的存储库,然后将其添加为你本地存储库中的 远程,并推送主分支(从而将本地存储库的副本与远程主机同步)。

请注意,如果有很多版本,这个过程可以自动化,但这种自动化大部分取决于你当前的 "文件版本管理" 结构,所以这取决于你。

英文:

Create a new directory, henceforth x, and cd x. Then run git init. This will start a new empty git repository inside the x directory. A git repository is a folder that has a .git subdirectory.

Copy the files from the first version of your project, paste them inside x.

Create a .gitignore file inside x and tell it which files of the project you do not wish be tracked by git. See here for more info.

After you're done, run git add -A to tell git to track all the files in the directory and prepare them for committing (this will add all files except for the ones mentioned in .gitignore).

Now run git commit -m "This is the first version of my project"

Now for the second version - completely overwrite all the files inside x with the files of the second version (by deleting everything except for .gitignore and .git and pasting the files of the second version). Then performs the commands similar to before:

git add -A

git commit -m "Second version of my project".

Repeat these steps for all versions - overwrite files, git add, git commit, repeat.

You now have a local git repository, with each commit corresponding to a version of your Java project.

You can see the differences between the versions using the git diff command or a Git GUI tool of your choice tool which allow you to explore your newly created repository.

You can now also upload your repository to a Git hosting service of your choice (popular ones being Github, BitBucket, GitLab and more) by creating an empty repository inside those services and adding it as a remote in your local repository and pushing the master branch (thus syncing the local copy of the repository with the remote host).

Note that this could be automated if you have a lot of versions, but such automation would largely depend on how your current "folder versioning" is structured, so this is up to you.

huangapple
  • 本文由 发表于 2020年8月13日 22:19:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/63397199.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定