Introduction to the

I mainly organize some parts that I use more in the company, so as not to say more, but more confused. If you want to learn detailed Git teaching, you can go to a special website. Equivalent to learning while remembering, common progress!

In this article, we will talk about the common command and function, the daily office is enough, and we can also search the function of a point to point to learn faster.

Git is the first thing you need to use, and a big reason is that your company needs to use it for code storage, so this article will focus on some of the most commonly used commands in your company.

As for some Git account configuration, this article will not say first, after waiting to write a special configuration Git. Mainly about the command.

 

The body of the

The most common commit process: first pull the server’s contents, then add your changes to the staging area, then commit the changes to the workspace, and finally push the changes to the server


Git add [filename] — Commit the change file to the staging area git commit -m “This change note” — commit the change file to the workspace git push origin branch-name Push to a branch


Git status — View the current status and list all new changes, Git log $git log –pretty=oneline — git reset –hard commit_id — go back to a version Git reflog — View command history

Git checkout –[file] Whether to add or delete the last time (return this file to submit the state) (cancel the git add | git commit) git reset HEAD [file] to the staging area change back to the low (cancel the git add) git reset – soft HEAD^ Cancel the git commit

Git reset --hard origin/master fetches code from the remote master branch, forgoing local changes and forcing updatesCopy the code

The advanced

Git clone [email protected]: michaelliao/gitskills will git clone git to own git library behind the address, can be clonedCopy the code

Git checkout -b [] git switch -c [] Git branch Git branch -d [] Deletes a branch git branch -d [] deletes a branch

Git log –graph –pretty=oneline –abbrev-commit git log –graph –pretty=oneline –abbrev-commit

Git stash is stored in the current working site git stash list view storage field git stash apply to recover the scene git stash drop to delete stored on-site git stash pop back and remove the git storage Stash apply stash@{0} Restores the specified storage site

Git cherry-pick [commit_id] Copy a specific commit to the current branch git cherry-pick –quit

Git remote add origin/[email protected]: liaoxuefeng/learngit. Git associated a remote repository git remote view remote library information git remote -v git to view more detailed information Remote rm Origin Deletes an existing remote library

Git push origin branch-name Git pull pull git checkout -b branch-name Origin /branch-name Create a branch git that corresponds to the remote branch Branch –set-upstream branch-name origin/branch-name Establishes the association between the local branch and the remote branch

Git tag -d

Git push origin git tag -d

git push origin Git push Origin :refs/tags/

can remove a remote tag.


$git config –global alias.co checkout

—————-

Problems in the process of use

1. Branch switchover

The green part of the first box represents the file that I have added git to, but have not yet committed git. The second box represents changes made to the original local file (without git add, etc.). The third box represents the newly added file. When I switch branches at this time, errors may be reported, because the files I modified may also exist in another branch. I modified the files of this branch, so I cannot switch to another branch, which will cause conflicts. If you want to switch branches, there are several ways to do this: Git checkout –[filename] restore the file to its last commit state. This is because local changes are deleted into the final commit state. 3. Git Stash Cut back, git Stash apply back to the latest stash. The Git Stash list shows multiple stash lists, going back to the previous stash based on the version shown.

2. Merge branches

Conflicts occur when merging branches

<<<<<<< HEAD
123
=======
12
>>>>>>> feature1
Copy the code

 

collaboration

Steps for a collaborative working mode:

  1. Step one, usegit push origin <branch-name>Push part of their modified content;
  2. If the push fails, the remote branch may be newer than your local branch, so useGit pull pulls remote content downAttempted merger;
  3. If the merge has a conflict, commit it locally once the conflict is resolved.
  4. Use only when there is no conflict or conflict is resolvedgit push origin <branch-name>Push will do

 

If git pull prompts no tracking information, the link between the local and remote branches has not been created. Git branch –set-upstream to

origin/

This is how people work together, and once you get used to it, it’s pretty easy.