November 1, 2017
1. Git Cheat Sheet
2. Check in Git Modified But Untracked Content
Recently, I migrate this site to Hexo. I download the theme from github to the Hexo project folder. I also keep the source code in the github in case I lost the source code. However, when I run the git add .
and git status
. It shows error messages saying the theme folder is not tracked content. Most time, I did not check the git status - bad habit. I only realize that I miss the theme files when I try to rebuild the Hexo site from home.
After searching a while form Google, I got my issues resolved and shared the steps below for reference.
- Removed the .git directories from the directories (In my case, ../theme/hueman/.git)
- Run
git rm -rf --cached <the untracked directory>
(In my case, /C/Users/ddu/Git/sparkera/themes/hueman) - Re-added the directories with a
git add .
and check bygit status
.
Then all the untracked files are added. Then you can do git commit -m
and git push
the submit all the changes.
3. Git Catch up Changes
There are following ways to catch up/revert changes in GIT
Catchup changes from remote
Pull out from remote again and you lost all of your local changes as well as hisory
rm -Rf working_folders git clone remote_git_address
Merge from remote and this keeps all your local changes
git pull
or
git fetch git merge
Catchup changes from local commit
Roll back all files to the latest commit and you lost all of your local changes not submitted
git reset --head HEAD
Roll back specific files to the latest commit and you keep all of other local changes not submitted
git checkout HEAD specific_file_name
Roll back all files to the latest commit and you lost all of your local changes not submitted. Hoever, this will submit a new commit as revert
git revert HEAD
Note:
- Git fast forward: It means code commit submmited should be ordered by time. To resolve the “non-fast-forward” error, you can use command 2 or 3.
git -f push
is not recommended since it forces push to remote.