Git study notes summary

Brief introduction

Before learning is Gittime to do a note to see that Liao Xuefeng of Git tutorial , no matter the holiday, so remember to sort out, to be sent to the csdn.

Day1

1, initialize a Git repository:

  • Create a new folder, right-click on the selected Git Bash Hereinput git initcommand.

2, add files to the Git repository, in two steps:

  • The first step in using the command git add <文件名>, pay attention, can be used repeatedly to add multiple files.
  • The second step uses the command git commit -m "注释信息"to complete the addition.

3, the modified file operations:

  • Use the command git statusto view the status of the work area.
  • Use the command git diffto view the content.
  • Before submitting modify and add files to the same steps Git repository.

4, version rollback

  • Use git logcommand to view your history in order to determine which version you want to go back retreated.
  • Use the git reflogView command history in order to determine what you want to return to a future version.
  • Use git reset --hard HEAD^fall back to the previous version, HEAD^on behalf of the previous version, HEAD^^the previous version of the delegates.
  • Use git reset --hard <提交的id号>fall back to a specific version.

5, understand the staging area

  • git addCommand is actually all modifications to be submitted into the staging area (Stage), then execute git committhe command can be one-time submission of all changes to the temporary area branch.


Day2

1, modify management

  • Each modification, if not git addcommand code into the staging area, then commitit will not submit this amendment.
  • Modify the file, but did not add to the staging area, it can be used git checkout -- <文件名>to discard modify the workspace.
  • Modify the document, while add to the staging area, the first step with a command git reset HEAD <文件名>to cancel add, and then git checkout -- <文件名>dropped to modify the workspace.

2, delete the file

  • Use rm <文件名>the command to delete a file, you sure you want to delete it with the command git rm <文件名>to delete, and with the git commit -m "备注信息"submission.
  • Mistakenly deleted can be git checkout -- <文件名>restored to the latest version.
  • git checkoutIn fact, the workspace is a replacement version with the version in the repository, regardless of the workspace is modified or deleted, can be "a key to restore."

3, add a remote library

  • Create a new folder, use the git initcommand, making it a local warehouse.
  • Open Git, run in the local repository git remote add origin <你的 github 上的一个远程库的地址>, for example: [email protected]:yueyueNSYW/learngit.gitso that you can remotely associated with the local library and the library again.
  • Use git push -u origin masterthe command, Git will put the local masterbranch of remote content push a new masterbranch, but also the local masterbranch and remote mastercan be simplified command associate branch, after such a push or pull.
  • After modifying the files in the local library and commitlater, you can use the git push origin mastercommand to the local masterlast modified branch pushed to GitHub .

Day3

1, from a remote library clones

  • Github now create a new project, to build a consistent folder with the project name locally, using the git initcommand to make it a local library, and then use the git clone <你的 github 上的这个远程库的地址>command to the remote library clones to the local library.
  • View branch:git branch
  • Create a branch:git branch <分支名>
  • Switching branches:git checkout <分支名>
  • Create a + to switch branches:git checkout -b <分支名>
  • Merging a branch to the current branch:git merge <分支名>
  • Deleted branches git branch -d <分支名>or git branch -D <分支名>(force deletion)
发布了11 篇原创文章 · 获赞 2 · 访问量 206

Guess you like

Origin blog.csdn.net/weixin_40242806/article/details/104077106