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

# Change the remote

git remote rm origin
git remote add 'the url'
git pull origin main
 
# Set the origin/main as the up stream
git branch -u origin/main main
 
# Push the branch wip to the remote origin
git push origin wip


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


======
To setup github ssh access
For error: ex_exchange_identification: Connection closed by remote host
 
I guess GFW make it.
By checking: https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port
which I followed the ~/.ssh/config added the port 443.
and use command like: "proxychains -q git pull", it is working now.

Here is what is working now through https, and through proxy:

❯ proxychains -q ssh -T git@github.com
The authenticity of host '[ssh.github.com]:443 ([20.205.243.160]:443)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[ssh.github.com]:443' (ED25519) to the list of known hosts.
Hi LeisureLinux! You've successfully authenticated, but GitHub does not provide shell access.


No comments: