1. init
git init
Copy the code
You can use git init to initialize a local Git repository.
2. config
git config --local user.name shawncheung
git config --local user.email [email protected]
Copy the code
Use git config to configure your personal information. I use –local because I don’t want githug information to interfere with my git daily use. Of course, you can also use –global.
3. add
git add README
Copy the code
Git add to index the README file
4. commit
git commit -m "commit message"
Copy the code
Use the git commit command to commit changes to the file to the cache
5. clone
git clone https://github.com/Gazler/cloneme
Copy the code
Use git clone to clone the remote repository by specifying a URL.
6. clone to folder
git clone https://github.com/Gazler/cloneme my_cloned_repo
Copy the code
Git clone -h specifies the path of the git clone url path to download the remote repository to a local folder.
7. .gitignore
nano .gitignore
Copy the code
Use your familiar text editor to edit the.gitignore file (nano in this case) The.gitignore file records files that need to be ignored at commit time to avoid unnecessary files being committed to the remote repository. Githug requires that all files with the.swp suffix be ignored, so it can be written like this:
.gitignore
*.swp
Copy the code
8. .gitignore includes
nano .gitignore
Copy the code
As in the previous level, we need to edit.gitignore files. This level requires that we ignore all.a files except lib.a, so.gitignore can be written like this:
*.a ! lib.a
Copy the code
The above! It means not included.
9. status
git status
Copy the code
This is a very common command used to check the current status of git caches and workspaces, often before git add. Git status git status git status git status Database.yml
10. Number_of_files_committed
git status
Copy the code
Git status: changed not stage for commit. Git status: changed not stage for commit. RubyFile5.rb
11. rm
git status
git add deleteme.rb
git commit -m "delete deleteme.rb"
Copy the code
A file was deleted from the hard drive, but not from the Git repository. You can use git add, git commit to actually commit the change. Git status: deleteme.rb git status: deleteme.rb
12. rm cached
git rm deleteme.rb
Copy the code
This scenario is very common. For example, if you accidentally add a file that you don’t want to add to the cache, you need to delete the added record, but not delete the file on your hard drive.
13. stash
git stash
Copy the code
Git maintains a stack to keep track of temporary changes. When using a Git Stash file, the file will revert to the previous commit state. When you need to use the changes again, you can restore them with git Stash pop{idx}. Often used to hold code to commit partial changes before pushing code.
14. rename
git mv oldfile.txt newfile.txt
Copy the code
You can rename oldfile.txt to newfile.txt, but only if oldfile.txt is tracked by Git first.
15. restructure
mkdir src
git mv *.html src
Copy the code
To move all.html files to the SRC folder, use the mkdir command to create a folder. Then use the git mv command to move all HTML files to the SRC folder using the wildcard re *.
16. log
git log
Copy the code
Record the hash value of the latest COMMIT. Each commit has a unique hash value to indicate that it is unique, and the Git log prints the commit list in chronological order, with the latest being first. Therefore, this chapter only needs to record the hash value of the first commit in git log to answer the question.
17. tag
git tag new_tag
Copy the code
Git tag tag_name Specifies the hash value of the current commit tag.
18. push tags
git push --tags origin master
Copy the code
Push all local commits with tags to the remote repository. This command is usually used in bulk situations where you need to package a Docker image for a COMMIT with a specific tag.
19. commit amend
git status
git add forgotten_file.rb
git commit --amend
Copy the code
This level requires adding forgotten files to the cache without using a new COMMIT. First use git status to see which file is missing, then use git add to add the file to the cache, and then use git commit –amend to modify the current commit. Make sure you don’t make git commit –amend after the commit has been pushed to the remote repository, because this changes the commit hash value and overwrites the original commit.
20. commit in future
git commit --date 2018-01-21
Copy the code
Provide a future time for the commit. The time format can be multiple, such as 2018-01-23. On Linux, you can run the date -r command to check the current time, and on Windows, you can run the date command to check the date. You can use the short 2018-01-21, or you can accept Mon, 3 Jul 2006 17:18:43 +0200, 2006-07-03 17:18:43 +0200, Mon Jul 3 15L18:43 2006. Even can accept – date = format: relative: 5. Hours. Relative time line. Git commit –date git commit –date git commit –date
21. reset
Git reset ${to_commit_first.rb commit hash} git status git log Git commit -m "add first" status // First file not passively added git commit -m "add first"
Copy the code
Changes to to_commit_second. Rb are not cached, so use git reset to rollback records to the desired time. Git reset HEAD^ resets the HEAD pointer back to the previous step.
22. reset soft
git reset --soft HEAD^
Copy the code
This level reverses the commit of the previous step, but retains the index. Reset takes three parameters: Soft, mixed, and hard. Soft will roll back the record, but will not overwrite changes to the index and workspace. Mixed will roll back the record and index, but will not overwrite changes to the workspace.
23. checkout file
git checkout -- config.rb
Copy the code
This level requires that all changes to the config.rb workspace be overwritten without reservation, and the contents of the previous file remain the same. Using the git checkout command, ensure that only the config.rb file overwrite is pulled from the remote end by setting — filename.
24. remote
git remote
Copy the code
This section uses git remote to view and record the remote repository name to answer questions.
25. remote url
git remote -v
Copy the code
Basically the same as the previous level, add the -v parameter to view the link of the remote warehouse, copy the remote warehouse down to answer the question.
26. pull
git pull origin master
Copy the code
Use the Git pull command to pull code from a remote repository.
27. remote add
git remote add origin https://github.com/githug/githug
Copy the code
Git remote add origin is the name of the remote repository, followed by the repository URL.
28. push
git status
git rebase origin/master
git push origin master
Copy the code
Use Rebase to merge with the remote master branch and push the changes to the remote end.
29. diff
git status
git diff app.rb
Copy the code
Use git diff to see where the app.rb file has been modified. Git diff does not specify the number of lines changed. Git diff does not specify the number of lines changed. Git diff does not specify the number of lines changed. Not Committed Yet information, the corresponding row is the modified row.
30. blame
git blame config.rb
Copy the code
Use the git blame command to quickly find the author of the most recently modified line on a given file, the commit, and when. You can quickly find out who changed the line of code in a team collaboration. The answer to this question is Spider Man.
31. branch
git checkout -b test_code
Copy the code
The purpose of this level is to show the benefits of branching. By creating a new branch, we can write our experimental code on the branch without affecting the original branch. Of course the above branches are abbreviations, you can also:
git branch test_code
git checkout test_code
Copy the code
32. checkout
git checkout -b my_branch
Copy the code
As in the previous level, create a new branch named my_branch.
33. checkout_tag
Git checkout v1.2
Copy the code
This level requires checking out to branch code with tag V1.2.
34. checkout_tag_over_branch
Git tag -l Git checkout tags/v1.2
Copy the code
Git checkout v1.2 is a branch of the repository with a tag of v1.2. If you use git checkout v1.2, you will switch to the v1.2 branch. You should first use git logs to view tags, and then use Git chekcout to switch the tag code.
35. branch_at
git log
git checkout -b test_branch <commit hash>
Copy the code
This level requires that a branch be created on a commit before the last commit, so you can use the Git log to view the commit history and copy the required commit hash to use in git Checkout.
36. delete_branch
git branch -d delete_me
Copy the code
To delete a branch, run the git branch command, using the -d parameter to specify the name of the branch to be deleted.
37. push_branch
git push --set-upstream origin test_branch
Copy the code
This section requires that only changes made on the local test_Branch branch be pushed to the remote repository. Use the –set-upstream parameter to do this.
38. merge
git checkout master
git merge feature
Copy the code
Merge the feature branch into the master branch. If the branch is not in the master branch, you need to merge the feature branch with the master branch.
39. fetch
git fetch
Copy the code
Gets the latest committed changes from the remote repository, but does not merge with the local repository.
40. rebase
git checkout feature
git add .
git commit -m "ready to rebase"
git rebase master
Copy the code
The feature branch is recorded as a smooth curve through rebase master.
41. rebase_onto
git rebase --onto master wrong_branch readme-update
Copy the code
This section requires that the README-update commit patch after the wrong_Branch is switched out be transferred to the Master branch. The feature branch is cut from the Develop branch, and we have some Develop bugs to fix. Then we forgot to checkout to the Develop branch and create a new branch on the feature branch. We had already committed several commits when we realized that the branch was created at the wrong point. Git rebase –onto base from to — git rebase –onto base from to — git rebase –onto base from to
42. repack
git repack -d
Copy the code
Git repack -d can clean up some garbage packing objects.
43. cherry-pick
git checkout new-feature
git log
git checkout master
git cherry-pick <need commit hash>
Copy the code
The commit on the new-feature does not meet the requirement and needs to be deleted, but only the readme changes need to be displayed in the master branch, so the cherry-pick command is required. The cherry-pick command repeats some commit on a branch. We need to switch to the new-feature branch to see the hash value of the commit, and then repeat it on the master branch.
44. grep
git grep --count TODO
Copy the code
Git git git git git git git git git git git git git git git
45. rename_commit
git log
git rebase -i <commit hash>
Copy the code
Git rebase -i git rebase -i git rebase -i git rebase -i git rebase -i Git rebase -i: git rebase -i: git rebase -i: git rebase -i
reword <commit hash> First coommit
pick <commit hash> Second commit
Copy the code
By default, both of them are pick commands. Change the first command to reword and enter the editing state of First Commit after saving the modification. Then you can rename the commit information.
46. squash
git rebase -i <commit hash>
Copy the code
In this level, you need to enter the reabse interactive command. This level requires you to merge several UPDATE readme commits into a single COMMIT. So the commit hash value here needs to be the commit hash before the commit that you need to edit, which is the initial commit. Then enter the edit state of COMMIT:
pick add readme
squash ...
squash ...
squash ...
Copy the code
Use a squash command to squash several commits. Note that you must have a pick command otherwise you cannot squash. Then save the changes and merge.
47. merge_squash
git status
git merge --squash long-feature-branch
git status
git commit -m "merge from long-feature-branch"
Copy the code
Merge the long-feature-branch branch into the master branch, but merge the long-feature-branch commit into one, Use the –squash parameter that requires git merge for merge.
48. reorder
git log
git rebase -i <commit hash>
Copy the code
Git rebase -i = git rebase -i = git rebase -i = git rebase -i = git rebase This level is initial commit. After entering the editing state, you only need to change the position of thrid commit and second commit to save it.
49. bisect
git log
git bisect start master <first commit hash>
git bisect run make test
Copy the code
Git bisect start is used to set the start node. Git bisect run uses the test file to determine the correctness of each commit to find bugs. All you need to do is answer the first seven bits of the commit hash from running the above command.
50. stage_lines
git status
git add -p feature.rb
Copy the code
Git add -p: delete the second commit file, save it and exit.
51. find_old_branch
git reflog
git checkout solve_world_hunger
Copy the code
Git reflog: git reflog: git reflog: Git reflog: Git reflog Git reflog is like a local undo library that records all of your local operations.
52. revert
git log
git revert <bad commit hash>
Copy the code
This level requires you to undo the changes made by the bad COMMIT. You can’t use reset locally because the commit has already been committed to a remote repository and you need to use Git Revert to fix it. Revert uses a reverse COMMIT to cancel out changes made by a previous commit rather than deleting the previous commit.
53. restore
git reflog
git checkout <commit hash>
Copy the code
Reset reset reset reset reset reset reset reset reset reset reset reset reset reset reset Git reflog allows you to see what you did earlier. Git Checkout is now ready to restore the commit hash.
54. conflict
git merge mybranch
Copy the code
This level requires the resolution of conflicts, which I believe many people have encountered in reality.
<<<<<<< HEAD
Categorized shoes by color
=======
Sat on a wall
>>>>>>> mybranch
Copy the code
In this case, between head and ==== is our local change, and between ==== and myBranch is myBranch change. The solution is to keep the part you want to keep, and then delete the characters (<, =, etc.). Add the file to git commit. This level will delete master changes.
Git add poem.txt git commit -m
Copy the code
55. submodule
git submodule add https://github.com/jackmaney/githug-include-me
Copy the code
Add a submodule to the repository using the git submodule add command.
56. contribute
This is the end of the game, if you are interested you can add your own code to the Githug game.