This is a note to read the official website of Liao Xuefeng and use it to look back later
1. Go to the project folder
Initialize a git repository, using git init
commands.
Add files to the Git repository in two steps:
The first step, use the command git add <file>
, note, can be used repeatedly, add multiple files;//
The second step, using git commit
the command, is done.
2. Modify the file
git status
command allows us to keep abreast of the current state of the warehouse, the above command tells us that Readme.txt has been modified, but not ready to commit the changes.
git diff
As the name implies is to view difference, the format is the UNIX common diff format, can be seen from the above command output
Commit the changes, use git add first, and use Git commit
3. Version rollback
- In Git, we use
git log
commands to view: The version control system must have a command that tells us the history,
- git log--reptty=oneline
- git reset--hard head^ (head^^: Last version, head~100: on 100 version) rollback to a version
- When you go back and want to return to the previous version, you'll know the version number.
- If you forget the version number git reflog: View the changelog for this library
4. The concept of workspaces and staging area
- Http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/ 0013745374151782eb658c5a5ca454eaa451661275886c6000
- Workspace: The file directory we see
- Staging Area: Modify logs in the. git folder and stuff like that (each version)
5. Management changes
- After modifying the file, use git add to add the changes to the staging area
- Then use commit, push the staging area changes to the branch (commit can only push the changes that have been add to the staging area, no add, there is nothing commit)
6. Undo Changes
git checkout -- readme.txt
Modifications to the workspace can be discarded
git checkout -- file
It is important in the command, --
no --
, it becomes the "switch to another branch" command, we will encounter the command in the later branch management git checkout
git reset HEAD file
You can undo the staging area changes (Unstage) and put them back in the workspace.
7. deleting files
If you are sure you want to delete the file from the repository, use the command to erase it, git rm
andgit commit
Delete the wrong, because the repository is still there, so it is easy to delete the deleted files to the latest version
8.github Warehouse:
- Connect your GitHub account first, using SSH: (tutorial) Http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/ 001374385852170d9c7adf13c30429b9660d0eb689dd43a000
- To connect, you'll need to add a library from the remote Library (GitHub website)
- Then perform the connection in the local library: git remote add origin git@github. Com:miaowwwww/learngit.git
- push Local to GitHub: Git push-u Origin Master (-U is required for first use, because not only will local files be pushed, but also local libraries will be built, and the GitHub repository is permanently connected)
- use after modification (after commit) $ Git push origin master
9. Cloning git
10. Branch Management
- Merge branch: $git merge Dev (switch back to the master branch, merging the current branch with the Dev branch)
- After the merge is complete, you can safely delete
dev
the branch:$ git Branch
11. Conflict resolution
- When two branches merge, there may be a conflict, after resolving the conflict, re-commit
git log --graph
you can see the branch merge diagram with the command.
12. Branch Management Policy
- Typically, when merging branches, GIT uses patterns when possible,
Fast forward
but in this mode, the branch information is discarded after the branch is deleted.
- If you want to force the mode to be disabled,
Fast forward
git will generate a new commit at merge, so you can see the branching information from the branch history.
- To prepare the merge
dev
branch, note --no-ff
The parameter, which indicates disabled Fast forwar
:
- $ git merge--no-ff-m "merge with No-ff" Dev
- You need to add-m to it because a new branch is created and you need to add a description
13.bug Branch: official website from Liaoche
- Each bug should be handled using a single branch: For example: ISSUE-101 branch, processing and then deleting branch
- Scenario 1: When the work on the Dev branch on the hand cannot be made on a commit, and must be processed issue-101, (do not create issue-101 directly, return to Dev, because there is no commit to staging area, and when you turn back, the part of Dev does not exist)
- Use $git stash: can put the current work site "storage", and so on after the resumption of the site to continue to work
- Repair issue-101, then back to Dev Branch and take out the stored code
git stash list 命令查看储藏列表
- One is with
git stash apply
recovery, but after recovery, stash content is not deleted, you need git stash drop
to use to delete
- Another way is to use
git stash pop
, restore the stash content also deleted
14.Feature Branch (new feature)
$ git checkout -b feature-vulcan
Before commit, say to cancel a new feature,git branch -D feature-vulcan (没commit,无法使用git branch -d feature-vulcan 删除,使用-D强制删除)
15. Use Remote GitHub Multiplayer collaboration: Everyone master
dev
pushes their changes on and off the branch. (Liaoche's official website)
- When you clone from a remote repository, git actually automatically corresponds to the local branch
master
and the remote master
branch, and the default name for the remote repository is origin
.
- git remote | | Git remote-v: View the Repository information
- Push branch: Git push Origin master<name>
- Capture Branch:
16. Label Management: Give a commit version an alias, not through a long string of version number
17. Ignore special files. Gitignore
git-Simple Process (study notes)