Use git manage file versions

Create Repository

  What is the repository of it? Warehouse repository, also known as the English name repository, you can simply understood as a directory, all files in this directory can be inside Git to manage, modify each file, delete, Git can be tracked so that any moment can be traced history, or you can "restore" at some point in the future. Since git is a distributed version management tool, it also has a complete git version management capabilities without the need for networking.

  Creating a repository is very simple, you can use git bash can also be used tortoiseGit. First, select a suitable place, create an empty directory

Use GitBash

  Select the Git Bash to start right-click in the current directory.

    

  Creating a warehouse execute the command:

    

add files

  Add File Process

    

      

      

      Changes to the text file with a "+" icon numbers:

      

      Documents: On mytest.txt right click again and select "Submit", then save the file to the repository.

      

      

       

 Work area and staging area

  Git and other version control systems such as SVN One difference is that the concept of the temporary area.

  What is the workspace (Working Directory)?

  Workspace is what you can see in the computer catalog, such as my reporstory folder is a work area.

  Some students might say repository is not a repository anyway how is the work area? In fact repository directory is the workspace in the directory ".git" folder is hidden repository. This time, a clear concept of it.

  The Git repository saved a lot of things, most important of which is called the stage (or called index) staging area, and the first branch master Git automatically created for us, and a pointer to the master called HEAD .

  As shown below:

    

  HEAD branch concept and we revisit it later. Speaking in front when we add files to the Git repository, and is performed in two steps:

  The first step is to use git add to add into the file, the file is actually added to modify the staging area;

  The second step is to submit changes with git commit, in fact, is to submit all the contents of the staging area to the current branch.

  因为我们创建Git版本库时,Git自动为我们创建了唯一一个master分支,所以,现在,git commit就是往master分支上提交更改。

  你可以简单理解为,需要提交的文件修改通通放到暂存区,然后,一次性提交暂存区的所有修改。

修改文件

  提交修改

      被版本库管理的文件不可避免的要发生修改,此时只需要直接对文件修改即可。修改完毕后需要将文件的修改提交到版本库。

      在mytest.txt文件上点击右键,然后选择“提交”

       

      

       

  查看修改历史

    在开发过程中可能会经常查看代码的修改历史,或者叫做修改日志。来查看某个版本是谁修改的,什么时间修改的,修改了哪些内容。

    可以在文件上点击右键选择“显示日志”来查看文件的修改历史。

      

      

   差异比较

    当文件内容修改后,需要和修改之前对比一下修改了哪些内容此时可以使用“比较差异功能”

      

      

  还原修改

    当文件修改后不想把修改的内容提交,还想还原到未修改之前的状态。此时可以使用“还原”功能

      

      

      

删除文件

  需要删除无用的文件时可以使用git提供的删除功能直接将文件从版本库中删除。

    

     

     

    

    

将java工程提交到版本库

  第一步:将参考资料中的java工程project-test复制到工作目录中

    

  第二步:将工程添加到暂存区。

    

    

    

     点击确定完成暂存区添加。  

  忽略文件或文件夹

    在此工程中,并不是所有文件都需要保存到版本库中的例如“bin”目录及目录下的文件就可以忽略。好在Git考虑到了大家的感受,这个问题解决起来也很简单,在Git工作区的根目录下创建一个特殊的.gitignore文件,然后把要忽略的文件名填进去,Git就会自动忽略这些文件。

    如果使用TortoiseGit的话可以使用菜单项直接进行忽略。

      

      

      

      

      

      

      

      

      

 

       

Guess you like

Origin www.cnblogs.com/wnwn/p/12088114.html