Git uses series 05-> file version management

Foreword

   如果惧怕前面跌宕的山岩,生命就永远只能是死水一潭。
   不想一篇博文写的过长,所以分割成两篇

1. Keep up with the previous article

Git file version management: https://www.cnblogs.com/dream66/p/12736657.html

Second, file version management combat

2.1 Delete files

  1. Create a new02.py file in the workspace c: \ git_repository with the content print ('new02')
  2. Use git add *, git commit -m "comment" to commit to the repository
  3. Delete the newly created new02.py file, there are two ways to delete it:

method one:

  1. Use the command git rm test02.py to delete, this operation will delete the files in the work area and add it to the temporary storage area synchronously
  2. Submit to the repository through the command git commit, at this time, the operation of deleting files in the work area and the temporary storage area has been completed

After the deletion is complete, if you want to undo the deletion, you can do the following:

The above is after the deletion is completed, if you want to undelete and use the version rollback to solve; if you want to perform the undelete operation after executing the git rm test02.py command, you need to command the operation as shown below:

The command:
git reset HEAD new02.py means to pull the last file submitted to the repository to the staging area. This operation does not affect the work area.
Git checkout-new02.py means to pull the staging area file and replace it Workspace file

Method 2:

  1. Delete the new02.py file by manual or system command, this operation will delete the file in the workspace
  2. Use the command git add -A to commit all changes in the work area to the temporary storage area
  3. Submit to the repository through the command git commit

After finishing the operation in the second way, you can also perform the undo delete operation as the rollback version operation described in the first way. If you only delete the new02.py file by manual or system command, and want to undo the deletion at this time, you can operate as shown below:

2.2 Rename file

  1. Create a new03.py file in the workspace c: \ git_repository with the content print ('new03')
  2. Use git add *, git commit -m "comment" to commit to the repository
  3. Rename the newly created new03.py file to test03.py, there are two ways to rename:

method one:

  1. Use the command git mv new03.py test03.py to perform a rename operation. This operation will rename the files in the work area and add them to the staging area synchronously.
  2. Submit to the repository through the command git commit

Readers of the undo rename operation can see the undo delete operation above, the operation of the rollback version is the same. If you want to perform the undo rename operation after executing the git mv new03.py test03.py command, the method is also the same as the delete operation, but there will be more test03.py files, at this time you can do the following two steps:

  1. Use git rm -r --cached test03.py to delete the test03.py in the staging area
  2. Manually or system delete test03.py file

Among them the command:
git rm -r --cached test03.py The effect of this command is that when we need to delete the file on the staging area or branch, but we need to use it locally, but we do not want this file to be versioned, we can use this command , Here we use to clear the file information of the temporary storage area

Method 2:

  1. Use manual or system renaming to rename the new03.py file to test03.py
  2. Use the command git add -A to commit all changes in the work area to the temporary storage area
  3. Submit to the repository through the command git commit

After the operation in Mode 2 is completed, you can also perform the undo rename operation as the rollback version operation described in Mode 1. If the new02.py file is renamed manually or by system commands, and you want to undo the rename at this time, you can operate as follows:

summary

  • In the article, the command is used to delete the file, and the reader can also directly delete or rename the file through the interface operation.
  • The method used in this article for file deletion and renaming is not unique, but the author's method is successful
  • I suggest that when you are new to git, do n’t use tools to perform graphical operations for the time being. You can use commands to complete it. Graphical tool operations can understand which command you are using.

Guess you like

Origin www.cnblogs.com/dream66/p/12739119.html