Recently I reviewed Git again, and at the same time I encountered some small problems with Git in my graduation project. Here I summarize some of them for myself and everyone

1. Prepare to submit the new project

When you create a new project directory and you intend to have something to submit

First, you need to make your project directory a git support directory

git init

Git status can be used to check the status of your workspace, the files you are modifying, and the branch you are in.

The next step is to add the modified files to the staging area with git add, which is usually used. Add all modification files

Git commit -m ‘Commit info

At this point, because of our new project submission, we need to set up the remote repository for our submission

Git remote add origin HTTPS: XXX

In the meantime, you can check with git remote -v to see if you have set it up

You can also use git remote rm Origin to delete the file

2. The submission

Git push < remote host name > < local branch name >:< remote branch name >

Git push Origin master:master, git push Origin PHR: PHR

Use Git push if you already have a remote branch to track

There are a few common mistakes that I’ve encountered

Updates were rejected because the remote contains work that you do

This error is caused by the inconsistency between the content of the remote repository and that of the local repository. So pull

git pull origin master

hint: Updates were rejected because the tip of your current branch is behind hint: its remote counte

The remote version of the remote repository is inconsistent with the remote version of the remote repository. Try pull

Git push -f origin master force push, be careful, force push after sure

fatal: refusing to merge unrelated histories

Sometimes this happens when we pull because we have a different version of the remote branch

git pull origin master --allow-unrelated-histories

Update with directives that allow different versions

3. When you want to go back on your word

Sometimes, when our workspace gets mixed up with code we didn’t expect, or we want to go back on some files we were working on, we can use code like this

Git checkout file nameCopy the code

or

`git checkout .` 
Copy the code

Discard all changes

There will be times when we pull remote code, or commit it incorrectly, and we want to go back to our commit state

In that case we can take a look at our submission information first

git reflog

Then we can find the previous submission information, for example

git reset --hard 32c1fac

conclusion

We have a lot of contact with Git, and there are a lot of problems, but we have laid a solid foundation, and we can solve the general problems. The first part is here first, everyone