In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use commands in git". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use commands in git".
Installation of git
This article uses the win7 platform. Git can be installed on Linux, Unix, Mac and Windows, and can be downloaded from the official website according to your own operating system.
Common git commands
Let's take a picture before introducing the command. all the commands revolve around the picture.
Workspace: the workspace, where you usually store the project code
Index / Stage: a temporary storage area for temporary changes to a file, but in fact it is just a file that holds information about to be submitted to the file list.
Repository: the local warehouse area (or version repository) is the location where the data is stored securely, which contains the data we submitted to all versions. Where HEAD points to the latest version in the repository.
Remote: a remote repository, a server that hosts code. After figuring out the above four concepts, let's start with practice.
Create a warehouse that Git can manage with the git init command (local library initialization)
Administrator@XCRBHXD05IEZEVS MINGW64 / d
$mkdir gitstudy
Administrator@XCRBHXD05IEZEVS MINGW64 / d
$cd gitstudy/
Administrator@XCRBHXD05IEZEVS MINGW64 / d/gitstudy
$git init
Initialized empty Git repository in D:/gitstudy/.git/
After executing this command, we can see that there will be an additional .git folder under the file, and everything under this folder (workspace) can be managed by git.
The git add command adds the file to the staging area. Let's create a demo.txt file (echo > file name)
$echo > demo.txt
Is the demo.txt file with a blue color at this time? When we execute git add-demo.txt
What if there are hundreds of files under this directory that have to be added to the temporary storage area? You can use git add. This command adds all files in the current directory to the staging area.
The git status view shows the status of the workspace and staging area.
$git status
The git commit-m "submit Information description" command adds the file to the local repository.
$git commit-m "first submission"
[master (root-commit) 22f0a2b] submit for the first time
1 file changed, 1 insertion (+)
Create mode 100644 demo.txt
Whether the demo.txt color turned green after submission.
The git commit-am "file description" [am] is the merge of the [add modify] two commands. For example, we modified two files, demo.txt and demo1.txt. At this point, we can directly use the git commit-am command
Git commit-am "third submission"
If new files are added, separate commands must be used, not merge commands.
Git add.
Git commit-m 'update' rollback unused git add (file must be commit passed)
When using git checkout-- filename (file name), notice that there is--
$git checkout-demo.txt
Rollback all file modifications using git checkout.
Git checkout. Git add is used, git commit is not used
Use git reset HEAD filename (specify a file name)
Git reset HEAD demo.txt
Rollback all files to modify git reset HEAD
Git reset HEAD
After using this command, the local changes will not disappear, but go back to the above unused git add cache code, continue to use git checkout-- filename, you can discard the local changes.
Git commit not push has been used
Git reset-- hard head ^ falls back to the state of the last commit (this command needs to be executed carefully). Head ^ (for last time) or through git reset-- hard (version number can be checked according to git log, commit will generate one each time)
Git reset-- hard head ^
Git reset-- mixed head ^ (--mixed can also be omitted), keep the workspace, and empty the staging area. Is to go back to before the last git add.
Git reset head ^
Git reset-soft head ^ resets the HEAD to the specified version without modifying the staging area and the staging area, which is suitable for merging commit nodes before going back to the last git commit.
Git reset-- soft head ^
Git revert will fall back to the previous commit, and a new commit will be generated. This fallback will be submitted as a modification record, with the advantage of not modifying the historical submission record.
Git revert e241441d8a85b2d89 has used push
Git push-f can perform the above operations locally and then force it to the remote warehouse.
Git push-f deletion
Git rm, this must be a file after commit.
Git rm demo.txt
Git rm-f this execution add does not execute commit can be deleted
Git rm-f 4.txt remote warehouse
The above operations are carried out in the local warehouse, and the submitted code cannot be seen by others. What if the hard drive is broken when writing the code? Does that mean all the code is gone? So when you finish writing the code, push it to the server.
Add a remote library
Use the command git remote add origin git@
Server-name:path/repo-name.git; Associated remote Warehouse
Be sure to create a warehouse remotely before associating
The first step is to sign up for an account on https://github.com/ 's largest gay Jiaoyou website in the world. Those who already have an account are ignored.
The next step is to build a new remote warehouse.
Git remote add origin git@github.com:workit1/studygit.git
Once associated, use the command git push-u origin master to push all the contents of the master branch for the first time.
Git push-u origin master
Later, after each local submission, you can use the command git push origin master to push the latest changes to the remote repository.
Clone from a remote library
Earlier, we learned how to relate remote libraries when there is a local warehouse and then a remote library. But in general, in actual development, we first have a remote warehouse, and then clone from the remote library.
Git clone https://github.com/workit1/gitstudy.git Branch Management
Git checkout-b means to create and switch branches
Administrator@XCRBHXD05IEZEVS MINGW64 / d/gitstudy (master)
$git checkout-b feature_a
Switched to a new branch 'feature_a'
The feature_a branch is created based on the master branch and switched to the feature_a branch.
Git checkout or git switch switch branch
Git checkout master
Git branch-a view all branches, including remote branches
Git branch view all local branches
Merge branches
Git merge master
When there is a conflict, there will be a state of merging.
Cancel the merge. If you don't want to merge at this point, you can cancel it using git merge-- abort.
Git merge-abort
Delete Branch
Delete local branch git branch-d
Git branch-d feature_a
Delete remote Branch git branch-D
What would it be like if we needed to develop a fully functional process in an actual project? Most corporate models should follow this process. 1. First, based on the trunk branch, pull out a functional branch (feature_xx) for development. two。 After the development is completed, the test is based on this functional branch. 3. After the test is complete, the developer merges the functional branch into the trunk branch. The merge code operation is as follows:
First switch to the trunk branch (release), and the trunk branch git pull drops down the latest code of the remote branch (some colleagues may have submitted the new code)
Switch back to the function branch and git merge the latest code of the local trunk to the current function branch. If there is a conflict in the merge, it will resolve the conflict and resubmit it.
Switch to the trunk branch to perform the git merge function branch. (this step can not be done by ordinary people in actual work.) the code must first initiate a merge request through the code review before it can be merged into the trunk branch.
After merging the trunk branches, the functional branches can be deleted.
Thank you for your reading, the above is the content of "how to use commands in git". After the study of this article, I believe you have a deeper understanding of how to use commands in git, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.