Skip to content

Latest commit

 

History

History
216 lines (174 loc) · 3.29 KB

git.md

File metadata and controls

216 lines (174 loc) · 3.29 KB

Git

List git-ignored files

git ls-files . --ignored --exclude-standard --others

List untracked files

git ls-files . --exclude-standard --others

Reset to last commit

git reset --hard

Reset specified file to last state

git checkout -- file.php 

Add files

git add path/file.txt

Remove file or files

git rm file
git rm -rf files

Revert Changes to File

git checkout -- <file>

Revert File to Previous Commit

$ git checkout <commit_hash> -- <file>

Diff and Merge, edit ~/.gitconfig

[merge]
        tool = kdiff3
[mergetool "kdiff3"]
        path = c:/Program Files/KDiff3/kdiff3.exe
[diff]
        tool = kdiff3
        guitool = kdiff3
[difftool "kdiff3"]
        path = c:/Program Files/KDiff3/kdiff3.exe
[core]
	editor = c:/Program Files (x86)/Subtitle Edit/SubtitleEdit.exe

KDiff3 download.

Merge

git mergetool

Generate and add key (Big Sur)

ssh-keygen -t ed25519 -C "your_email@example.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Add key to a remote server, and set the permissions

nano authorized_keys
chmod 644 authorized_keys

View your key

cat ~/.ssh/id_ed25519.pub

Set your identity

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Ignore file .gitignore example

# Designers
*.psd

#OS junk files
[Tt]humbs.db
*.DS_Store

# Sync Tools
sync.ffs_db

# Damn dreamweaver
*_notes/

# Builds
/build/OTAInstall
/build/StandardInstall

# Config files
config.php
config.json

SSH Git using non standard ports, create alias on ~/.ssh/config file:

Host bitbucket.org
        HostName altssh.bitbucket.org
        Port 443

Sync GitHub pages method 1

git commit -m 'Info'
git push origin master

# New branch
git checkout -b gh-pages

# Switch to existing branch
git checkout gh-pages

git merge master
git push origin gh-pages
git checkout master

Sync GitHub pages method 2

  1. Go to the gh-pages branch
  2. Bring gh-pages up to date with master
  3. Commit the changes
  4. Return to the master branch
git checkout gh-pages
git rebase master
git push origin gh-pages
git checkout master

See local branches

git branch

See remote branches:

git branch -r

See all local and remote branches:

git branch -a

Create new branch

git checkout -b <newbranch>

Push to an scpecific branch

git push origin <branch>

Switch to a branch

git checkout <branch>

Create patch from last commit, add ~ for extra commits:

git format-patch HEAD~

Apply patch:

git am commit-name.patch

NPM

npm login
git commit -m "Blah"
git tag v0.1.0
git push origin master --tags
npm publish

Source: https://codeburst.io/how-to-create-and-publish-your-first-node-js-module-444e7585b738

Non-git patchs

Create a patch and applying

diff -Naur original modified > patch.txt
patch original < patch.txt

Create, apply and undo

diff -u OriginalFile UpdatedFile > PatchFile
patch OriginalFile < PatchFile
patch -R OriginalFile < PatchFile

Source: https://www.shellhacks.com/create-patch-diff-command-linux/