Wednesday, 4 January 2023

Git commands

git-shell commands:

Git Local Config

git config --global user.email: showing current git user default email. 

git config --global user.name "John Doe": config git user name 

git config --list : check your local git config 


As committing
git init: creating a local git repository, i.e. .git in the current folder.
git add . : adding all files in a current folder for commit
git add filename.* : adding a specific file in the current folder for commit
git commit -m 'another commit' : commit added files to the local repository with a commit message.
git commit -a : commit all changes in the current dir.
git commit -am "message": commit all changes with a message in the current dir.
git remote add origin https://github.com/yichunzhao/Java8.git : link local repository to remote repository.
git push -u  dst  src ; git updating remote with a local source; -u: update

git remote rm origin: disconnect the link with the remote repository.

git pull: it is a shorthand for git fetch + git merge fetch_head

Info. 
git status: current branch status.
git remote -v  v: verbose displaying info. of remote repository

Branch 
git branch -r: remote branches
git branch: local branches

git branch -d|D branch-name: removing a local branch
git branch -d|D combined with -r branch-name: removing a remote branch

Push 
git push --set-upstream origin red: push local feature branch to the remote, when at the first time.

Stash 
git stash
git stash show

git stash show stash@{1}

git stash list : list all stash
git stash apply: applying the most recent stashed changes
Or
git stash pop : applying the most recently changes to your repo. 


Creating a new branch
git branch dev
git checkout master:  switching to another branch.

View history
git log :
git log --oneline
git reflog
git log --all --graph --decorate --online
git diff: working directory, a difference between commits

Switching between different branches
git checkout master: switch to master branch
git checkout dev: switch to the dev branch

by default, a remote repository is named as an origin by Git.
git push origin dev: push dev branch to the remote by the following command:

Removing a file or folder
git rm x.text
git commit -m "removing a file"
git push origin dev: don't forget to update remote

Git Merging
as standing on the master and merging changes from dev branch in
git checkout master
git merge dev
git add .  : add all changes from the dev branch
git commit -m "changes from dev"
git push origin master: commit local master into remote

When conflicts happen
git merge -- abort: get back the state before merge conflicts

editing confliction; OR:  choose

Alternatively, you can tell Git that you'll simply go with one of the edited versions, called "ours" or "theirs".

git checkout -- ours path/to/conflict-file.css

git checkout -- .  : git discard all changes that are not staged for commit

merger from a feature branch into local master

git checkout master
git pull
git checkout feature
git merge master

Git Revert
git revert undoes a specific commit and then creating a new commit.

git revert by default pops up a vi editor to modify the commit message; press ESC to command line, ZZ(Capital) command to save the file.

git revert specific-commit --n
git revert specific-commit -- no-edit

git log --oneline: it shows the commit ref(s)
git reflog

git revert commit-ref: then modifying the commit message; normally using the default text revert xxx

Press ESC, shift zz; then quit from the vi editor.
git log: it shows a revert commit created.

Git Reset

git reset: having three types of invocations. --soft(the commit tree head), --mixed(stagging index), or --hard(working directory).

Git/Linux Command
ps -ef|grep git: checking git process running
rm -f .git/index.lock : remove index locker file located in the ./git folder

Git Remove remote folder
making sure you are at the right branch
git checkout branch-expected
git rm --cached -rf ./.idea; -rf:  recursive and force
git commit -m "rm remote folder"
git push 

Git Remove remote and local folder
#remove a file
git rm password.text

#remove a folder
git rm -rf ./.idea

Config git

It allows to config git user name and email.

git config --global user.name "my-user-name"
git config --global user.email "my-email"

Git ignoring

Git disconnect remote repository

git remote -v: display all remote repositories linking to local repo.
git remote add remote_repo_name another_remote_git_repo_url: pointing to local repo. to another remote repo.
git remote rm remote_repo_name: removing the link to the remote repo, not rm remote repo.


No comments:

Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...