openHacking / xhack

js util
1 stars 0 forks source link

git command #47

Open openHacking opened 2 years ago

openHacking commented 2 years ago
  1. Git global setup

    git config --global user.name "openHacking"
    git config --global user.email "openHacking@126.com"
  2. Create a new repository

    git clone https://github.com/openHacking/xhack.git
    cd xhack
    touch README.md
    git add README.md
    git commit -m "add README"
    git push -u origin master
  3. Push an existing folder

    cd xhack
    git init
    git remote add origin https://github.com/openHacking/xhack.git
    git add .
    git commit -m "Initial commit"
    git push -u origin master
  4. Set up local account to push an existing folder

    git init
    git config --local user.name "openHacking"
    git config --local user.email "openHacking@126.com"
    git add .
    git commit -m "init"
    git branch -M main
    git remote add origin https://openHacking@github.com/openHacking/xhack.git
    git config --local credential.helper store
    git push -u origin main
  5. Push an existing Git repository

    cd xhack
    git remote rename origin old-origin
    git remote add origin https://github.com/openHacking/xhack.git
    git push -u origin --all
    git push -u origin --tags
  6. Edit origin url

    git remote set-url origin https://openHacking@github.com/openHacking/xhack.git
  7. Delete all commit history in git

Deleting the .git folder can cause problems in the git repository. If you want to delete all commit history, but keep the code in its current state, you can do it safely as follows:

# Try running 
git checkout --orphan latest_branch

# add all files 
git add -A

# Commit changes 
git commit -am "commit message"

# delete branch 
git branch -D master

# Rename the current branch 
git branch -m master

# Finally, force an update of the repository
git push -f origin master
  1. Only push tag
    
    # check latest tag
    git describe

generate new tag

git tag -a release-v0.0.0 -m "msg"

push tag

git push origin release-v0.0.0

9. Push commit with tag
```sh
git add .
git commit -m "msg"
git pull
git describe
git tag -a release-v0.0.0 -m "msg"
git push --follow-tags
  1. git undo commit

    git reset HEAD .
  2. merge branch

How to merge dev branch to main branch?

Submit the code of your own dev branch before merging

# 1. Enter the branch to be merged (if the dev branch is merged into main, enter the main directory)
git checkout main
git pull

# 2. Check whether all branches have been pulled down
git branch -a

# 3. Use merge to merge dev branch
git merge dev

# 4. View the status after the merger
git status

# 5. If there is a conflict, resolve the conflict through the IDE;

# 6. After resolving the conflict, submit the conflict file to the staging area
git add .

# 7. The result after submitting the merge
git commit -m "fix conflict"

# 8. Submit the local warehouse code to the remote warehouse
git push
  1. pull develop branch
    git fetch origin dev
    git checkout -b dev origin/dev
    git pull origin dev
MintZzz1009 commented 2 years ago

This is a good description!

openHacking commented 2 years ago

This is a good description!

Thanks