MJay

GitHub Useful Commands - Part1 본문

Git

GitHub Useful Commands - Part1

MJSon 2019. 3. 27. 23:07

Commiting changes

echo '*.tmp' > .gitignore

git difftool

git difftool --staged -> stage 별로 확인이 가능하다

git log --pretty=format:"%h %an %ar - %s"

git show - for author's information 와 함께 보여준다

Work Remotely

git remote add branch

git push origin master

git pull origin master

git log --grep="#1234"

git branch -r

The command git pull is a combination of two different commands, git fetch and git merge. Fetch downloads the changes from the remote repository into a separate branch named remotes//. The branch can be accessed using git checkout.

Undo changes

When working with Git, a common scenario is to undo changes in your working directory. The command git checkout will replace everything in the working directory to the last committed version.

If you want to replace all files then use a dot (.) to indicate the current directory, otherwise a list the directories/files separated by spaces.

git checkout .

If you're in the middle of a commit and have added files to the staging area but then changed your mind then you'll need to use the git reset command. git reset will move files back from the staging area to the working directory. If you want to reset all files then use a . to indicate current directory, otherwise list the files separated by spaces.

This is very useful when trying to keep your commits small and focused as you can move files back out of the staging area if you've added too many.

git reset HEAD .


A git reset --hard will combine both git reset and git checkout in a single command. The result will be the files removed from the staging area and the working directory is taken back to the state of the last commit.

git reset --hard HEAD


If you have already committed files but realised you made a mistake then the command git revert allows you to undo the commits. The command will create a new commit which has the inverse affect of the commit being reverted.

If you haven't pushed your changes then git reset HEAD~1 has the same affect and will remove the last commit.

git git revert HEAD --no-edit [master f59e894] Revert "Commit To Revert" 1 file changed, 1 insertion(+), 1 deletion(-)

To revert multiple commits at once we use the character ~ to mean minus. For example, HEAD~2 is two commits from the head. This can be combined with the characters … to say between two commits.

git git revert HEAD...HEAD~2 --no-edit


'Git' 카테고리의 다른 글

GIthub의 Repository란  (0) 2017.10.15
GitHub 몇가지 정리  (0) 2017.10.13
github 사용법  (0) 2017.05.23
CPU bound & I/O bound  (0) 2017.03.18
Git Merge &Rebase  (0) 2017.03.17