Difference between revisions of "Git"

From UVOO Tech Wiki
Jump to navigation Jump to search
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
# Checkout PR
 +
 +
Let's say pr144 is PULL Request ID
 +
```
 +
git fetch origin pull/144/head:pr144
 +
git checkout pr144
 +
```
 +
 
# Git Common Commands
 
# Git Common Commands
 
+
- https://link.medium.com/rNTHPuPgPdb
  
 
```
 
```
Line 23: Line 31:
 
# Showing Changes
 
# Showing Changes
 
- https://stackoverflow.com/questions/48570464/what-is-the-git-command-used-by-github-pr-to-show-differences
 
- https://stackoverflow.com/questions/48570464/what-is-the-git-command-used-by-github-pr-to-show-differences
 +
 +
```
 +
git ls-remote origin
 +
```
  
 
hosts.txt
 
hosts.txt
Line 33: Line 45:
 
```
 
```
 
for i in $(git diff master...pr -- hosts.txt | grep "^+" | grep -v "^++" | cut -c2-); do echo add $i; done
 
for i in $(git diff master...pr -- hosts.txt | grep "^+" | grep -v "^++" | cut -c2-); do echo add $i; done
 +
```
 +
 +
simple file compare
 +
```
 +
for i in $(git diff hosts.cur hosts.new | grep "^+" | grep -v "^++" | cut -c2-); do echo add $i; done
 +
```
 +
 +
```
 +
git log --oneline -n 10
 +
git checkout <my hash>
 +
 +
or other option
 +
git reset --hard HASH-CODE
 +
```
 +
 +
Rename branch
 +
```
 +
git branch -m main dev
 +
git fetch origin
 +
git branch -u origin/dev dev
 +
git remote set-head origin -a
 +
```
 +
 +
```
 +
GIT_SSH_COMMAND='ssh -i  ~/.ssh/repos/foo' git clone git@github.com:uvoo/foo.git
 
```
 
```

Latest revision as of 20:57, 13 February 2023

Checkout PR

Let's say pr144 is PULL Request ID

git fetch origin pull/144/head:pr144
git checkout pr144

Git Common Commands

git reset --soft HEAD~1  # Keep changes

git reset --hard HEAD~1  # Discard changes

ref: https://www.git-tower.com/learn/git/faq/undo-last-commit

git clone git@github.com:jeremybusk/myrepo.git
git checkout --orphan temp_branc
git add -A
git commit -m "add files"
git branch -D master
git branch -m master
git push -f origin master

wipe history - you can use git clone as well or just copy files to new repo

Showing Changes

git ls-remote origin

hosts.txt

host1,up
host2,up

Show new lines

for i in $(git diff master...pr -- hosts.txt | grep "^+" | grep -v "^++" | cut -c2-); do echo add $i; done

simple file compare

for i in $(git diff hosts.cur hosts.new | grep "^+" | grep -v "^++" | cut -c2-); do echo add $i; done
git log --oneline -n 10
git checkout <my hash>

or other option
git reset --hard HASH-CODE

Rename branch

git branch -m main dev
git fetch origin
git branch -u origin/dev dev
git remote set-head origin -a
GIT_SSH_COMMAND='ssh -i  ~/.ssh/repos/foo' git clone git@github.com:uvoo/foo.git