8/29/2016

GIT commonly used commands

# How to remove unwanted file from last commit
git reset --soft HEAD~1
Then reset the unwanted files in order to leave them out from the commit:
git reset HEAD path/to/unwanted_file
Now commit again, you can even re-use the same commit message:

git commit -c ORIG_HEAD

# How to resolve conflicts
After git rebase "branch", there may be conflicts.
If you want to accept the changes from the "branch" , just run:
git checkout --ours
Or If you want to accept the changes from current branch, just run:
git checkout --theirs

Or
git rebase -s ours

How to fix this error: error: The following untracked working tree files would be overwritten by merge:
git fetch --all
git reset --hard origin/master




Submodules
=========

g submodule add https://github.com/google/protobuf.git third_party/protobuf
g submodule update --init  # to clone all submodules

How to re-init submodules
emacs .git/config: delete all submodule related items
Then run: git submodule init


After git pull in the main repo, need to run the following commands:
git submodule sync --recursive
git submodule update --recursive


git diff shows no changes, but git status shows a list of modified files:
Open .git/config and make sure:
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        ignorecase = true
        autocrlf = false
        symlinks = false





No comments: