Good FAQ Web Site: here
GitHub Desktop은 Git의 일부 중요한 기능(명령)만을 발췌하여 쉽게 사용하도록 만든 윈도우 인터페이스 적용한 프로그램입니다. 그러므로, 좀 자세하고, 다양한 Git의 기능을 사용하려면, Console에서 Git 명령어를 사용하여 우리가 필요한 작업을 해야합니다. Git을 사용하려면, git도 설치해야 합니다.
예를 들면, nowic를 clone하여 사용하다보면, 때때로 nowic에서 파일을 고치고, 새로 만들기 하고, 실수로 파일을 삭제하기도 하며, nowic가 원본(origin/master)과 많이 달라질 수 있습니다. 이럴 때, 종종 우리는 local files를 원본으로 동기화해야 할 때가 있습니다. 물론, nowic를 자체를 삭제하고, 새로 clone을 할 수도 있지만, 아래와 같은 방법으로 local files을 모두 동기화(Overwrite)할 수 있습니다.
- At a console, go to the root of your repository (e.g. ~/nowic folder)
- Run one of the following commands, depending on your need
CASE 1: You Don't Care About the Local Changes
git fetch
git reset --hard HEAD
git merge origin/$CURRENT_BRANCH
CASE 2: You Very Much Care About the Local Changes
git fetch
git stash
git merge origin/$CURRENT_BRANCH
git stash pop
Note 1: Git has a nice shortcut pointing to the upstream branch: @{u}
. An upstream branch is the branch in the remote repository that you push to and fetch from. The followings are the same.
git merge origin/$CURRENT_BRANCH
git merge '@{u}'
Note 2: git fetch
downloads the latest from remote without trying to merge or rebase anything. Then the git reset
resets the master branch to what you just fetched. The --hard
option changes all the files in your working tree to match the files in origin/master
Note 3: If you have any local changes, they will be lost. With or without --hard option, any local commits that haven't been pushed will be lost.
- At a console, go to the root of your repository (e.g. ~/nowic folder)
- Open a console and run the following command.
git clean -f -d
Explanation: To delete all untracked files.
Simply move (if you use GitHub desktop) the whole repository folder contents (including the hidden .git folder). This will move the entire folder to the new location and will not affect the remote repository on GitHub. (If you use a git user, you may use copy
instead of move
command for your safety.)
For GitHub Desktop users: After moving, however, let GitHub Desktop know where your new repository location is.
Explanation: There is no absolute path in the .git structure and nothing preventing it to be moved so you have nothing to do after the move. All the links to GitHub (see in .git/config) will work as before.
git reflog
will display any change which updated the HEAD and checking out the desired reflog entry will set the HEAD back to this commit.
- Every time the HEAD is modified there will be a new entry in the reflog
- The following command get you back to your desired commit.
git reflog
git checkout HEAD@{...}
- "Move" your HEAD back to the desired commit.
- This will destroy any local modifications.
- Don't do it if you have uncommitted work you want to keep.
or
git reset --hard 0d1d7fc32
git reset --hard HEAD~1
- Alternatively, if there's work to keep:
- This saves the modifications, then reapplies that patch after resetting.
- You could get merge conflicts if you've modified things which were changed since the commit you reset to.
or
git reset --hard 0d1d7fc32
git reset --soft HEAD~1
git reset HEAD~1
---- Keep the local changesgit reset --hard HEAD~1
---- YOUR CHANGES WILL BE LOSTgit reset --soft commit_id
---- Keep the local changesgit reset --hard commit_id
---- YOUR CHANGES WILL BE LOST
- git log -n 4 displays the last 4 commit with hashes
- git reflog displays commit's HEAD
- git show /path/filename
- git status
- git checkout file1 file2 ---- undo it if the file is not committed.
- git checkout file1 file2 --- undo it if the file is already committed.
- git reset filename -- undo it if the file is already committed
- git checkout HEAD^1 path/to/file -- undo it one revision back
-
HEAD^1 is the first parent and HEAD~1 is the second parent.
One thing I know, I was blind but now I see. John 9:25