Skip to content

💥 FAQ

SkyLull edited this page Apr 18, 2024 · 4 revisions

Why is my ssh-key not working?

Please check if your remote url looks like [email protected]:{USERNAME}/{REPOSITORY}.git

  • You can find it in Logseq graph folder/.git/config.

How to fix error: The current repository is not synchronized with the remote repository, please check.

cd in your Logseq graph folder in terminal and type git fetch --prune.

How to fix error: Permission denied:(publickey).

Have you established ssh connection with github yet?

If you haven't, please refer to this tutorial

If you did, you might need to add a config telling ssh to use a specific credential !

Here's how it work:

  1. Add a file named config (without any extension) under ~/.ssh
  2. Edit it using your preferred text editor, add following text into the file
# github
Host github.com
    User git
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile <path to your private key file>
    ServerAliveInterval 300
    ServerAliveCountMax 10
  1. Test if it worked using command
ssh -T github.com

Why and how to fix error: "fatal: not in a git directory"?

It happens after git v2.35.2. git v2.35.2 add safe.directory option to solve CVE-2022-24765.

If user haven't add the path of the repo to ~/.gitconfig, it will show similar error to prevent user to use git commands.

Use git config --global --add safe.directory <git folder> to solve the issue.

What is Rejected push?

Rejected push happens when the remote (eg, GitHub) contains modifications that you have yet to download. This can happen if you forgot to do a pull in your local version before commitng new changes to it.

What is Git Conflict?

Git conflict happens when you have two commits, one local and the other remote, which modify the same file in the same lines.

What is Trailing whitespace?

Trailing whitespace happens due to two reasons:

  1. CRLF : Windows uses CRLF(carriage return line feed: \r\n) and Unix uses LF(line feed \n).
  2. Trailing whitespace: File contains lines ending with space.

Why do I need to know how to solve rejected push & Git conflict?

Rejected push and Git conflict are something every Git users will meet eventually. It's important to know how to solve them.

Case study

For example, You type "I'm faithful to Logseq." in your journal on your pc, but you also type "Na, I also use other note-taking tools." in your journal on your phone at the same time. GitHub will accept the first commit you push to it. But when you push the second commit, Git will say something like:

error: failed to push some refs to 'github.com:{your-username}/{your-reponame}.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

which basically means: "WTF Bruh, I can't believe you just lied to me. How can I trust you again?"

So you type git pull in your Git Bash/iTerms/Termux to gain GitHub's trust again, like what Git suggested in hint:. And that's how to resolve most of the rejected push.

However, sometimes that's not enough. After using git pull to update your local repo, Git will say:

Auto-merging {the conflict file} #e.g. journals/2022_04_23.md
CONFLICT (content): Merge conflict in {the conflict file}
Automatic merge failed; fix conflicts and then commit the result.

which means you have to manually delete which part you don't want.

So you open {the conflict file} with whatever text editor you like and fix it.

In the text editor:

<<<<<<< HEAD
- I’m faithful to Logseq. # Ok, I choose to keep this part.
=======
- Na, I also use other note-taking tools.
>>>>>>> 744f5cf94a46da43f5b318dab74c0f672bae31e2

After deletion:

- I’m faithful to Logseq.

Open Logseq and that let Logseq do the rest (Logseq will commit and push due to git hooks setting.) for you, and the Git conflict should be resolved. Now you should only see the chosen part remain in your GitHub repo. And you are again a happy Logseq user now! 😍

NOTE: For Android users, you have to manually commit and push the changes since your workflow does not contain git hooks I provided.

NOTE: Sometimes, it's the logseq/metadata.edn or logseq/pages-metadata.edn having Git conflicts. This is trickier because you cannot tell easily which part is the one you need to keep. In this case I would suggest simply remove logseq/metadata.edn or logseq/pages-metadata.edn and do a git pull again, that will restore it from the one coming from GitHub. After pulling logseq/metadata.edn or logseq/pages-metadata.edn from GitHub, Re-index and Refresh Logseq are advised.

Trailing whitespace handling

In your Git Bash/iTerms/Termux, turn off crlf check in your Git config.

git config --global core.autocrlf false
git config --global core.safecrlf false

and try to push again.

If that's not enough, add below code in your .git/hooks/pre-commit to remove trailing whitespace.

if git rev-parse --verify HEAD >/dev/null 2>&1
then
    against=HEAD
else
    # Initial commit: diff against an empty tree object
    against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 # <the first commit id of your repo>
fi

# Find files with trailing whitespace
for FILE in `exec git diff-index --check $against -- | sed '/^[+-]/d' | (sed -r 's/:[0-9]+:.*//' > /dev/null 2>&1 || sed -E 's/:[0-9]+:.*//') | uniq` ; do
    # Fix them!
    (sed -i 's/[[:space:]]*$//' "$FILE" > /dev/null 2>&1 || sed -i '' -E 's/[[:space:]]*$//' "$FILE")
    git add "$FILE"
    echo "NOTE: removed trailing whitespace from $FILE"
done

and try to push again.