Study
- setting user name, email
git config --list ## show global list
git config --global user.name "Hwang Yunho" ## set user name
git config --global user.email "hwang9yh@gmail.com" ## set user email
- You can use branch command when you want to see branch list. Below is branch command examples.
git branch ## shows local branch list
git branch -r ## shows remote branch list
git branch -a ## shows local and remote branch list
git branch [new branch] ## checkout new branch
- If you want to delete local branch [example]
git checkout master
git branch -d example
- And you also want to delete the branch from remote server. Then delete local branch and add one line.
git push origin :example
- You can upload your source files.
- Check your local branch which files are unstaged.
git status- Then choose files and add.
git add example.html example2.html ## this command adds files which you select
git add . ## this command adds all the files which are unstaged files
- Next, write the commit messages
git commit ## If you enter this command, then your cgi turns on commit write pages
git commit -m "[commit message]" ## You can write your command easily- Finally push your commit
git pushSome push way
- push local branch to remote branch
git push [remote server] [local branch]:[remote branch]- push local branch to same name remote branch
git push [remoete server] [local branch]- You pull sources from remoete server
git pull- you can checkout another branch from current branch. If you have same branch names, you only checkout.
git checkout [branch]- merge with no commit
gir merge [branch]- This command shows the current branch stage status.
git status- The current sources changed, and you don't want to push to server then enter this command. This command stores the current status to the stash stack.
git stash ## store the current status
git stash list ## Show all stash list
git stash apply ## This command applies the last git stash and the last git stash remains on stash list
git stash apply stash@{number} ## This command applies stash@{number}. Number is stash index from 0~
git stash pop ## This command pop up the last git stash
git stash drop ## This command drops stash@{0}
git stash drop stash@{number} ## This command drop stash@{number}. Number is stash index from 0~
git stash clear ## This command drops all stash stack.
- git commit
- If you want to some commits not merged, and another commit needs merge.
git cherry-pick [commit-hash]- This command shows commit log
git log- But, this command only shows commit-hash and date. So there is option -p. So you can shows the source code change.
git log -p
git log -p [commit-hash] ## you cah shows from the commit-hash
git log --since="2018-11-01" --author="yhmane" ## shows the log since the day that commit user == author- This command shows release version
git tag ## shows the tagging version ex) v1.0 v1.1 ...
git tag -l v1.1.* ## find and show the version like v1.1.1 v1.1.2 ....
- Add tag. There are two ways adding tag.
git tag v1.0 ## First way is Lightweight Tag. It only shows the version.
git tag -a v1.0 -m"Release version 1.0" ## Second way is Annotated Tag. It shows person, email, date, and messages
- Push tag to remote repository
git push origin v1.0 ## only push v1.0
git push origin --tags ## if you want to push all tags, then use this command.
- Delete tag
git tag -d v1.0 ## delete tag local branch.
git push origin :v1.0 ## delete tag from remote repository.
- This command removes untracked files from the working tree
git clean [-d] [-f] [-i] [-n] [-q] [-e ] [-x | -X] [--] …...
git clean -f ## removes untracked files
git clean -fd ## removes untracked directories and files
- This command shows what revision and author last modified each line of a file
- If you use this command with git diff command, you can get difference or errors more effectively
git blame [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental]
[-L ] [-S ] [-M] [-C] [-C] [-C] [--since=]
[--progress] [--abbrev=] [ | --contents | --reverse ..]
[--]
git blame [file] ## shows last commit msg&author of file from start to end
git blame -L 5,9 [file] ## shows last commit msg&author of file line 5~9
- This command reapplies commits on top of another base tip. But I don't recommend this command.
git rebase -i HEAD~ ## This command shows N~HEAD, N-1~HEAD ... , HEAD
## Then you can choose pick, squash, reword, edit, fixup, exec, drop
pick = use commit
reword = use commit, but edit the commit message
edit = use commit, but stop for amending
squash = use commit, but meld into previous commit
fixup = like squash, but discard
exec = run command using shell
drop = remove commit
if you choose the command, then rebase start.
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To check out the original branch and stop rebasing run "git rebase --abort".
If you push commit remote server, then I never recommend rebase ...