git 清空所有commit记录方法

说明:例如将代码提交到git仓库,将一些敏感信息提交,所以需要删除提交记录以彻底清除提交信息,以得到一个干净的仓库且代码不变 1.Checkout git checkout –orphan latest_branch Add all the files git add -A Commit the changes git commit -am “commit message" Delete the branch git branch -D master 5.Rename the current branch to master git branch -m master 6.Finally, force update your repository git push -f origin master
Read More ~

git撤销与回滚

git的撤销与回滚在平时使用中还是比较多的,比如说我们想将某个修改后的文件撤销到上一个版本,或者是想撤销某次多余的提交,都要用到git的撤销和回滚操作。撤销分两种情况,一个是commit之前,一个是commit之后,下面具体看下这两种情况。 一.git commit之前 未添加到暂存区的撤销(没有git add) 添加进暂存区的撤销(git add后) 复制代码 $ git status On branch test_git Changes not staged for commit: 没有添加到暂存区 (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory)     modified: new_src/app/Http/Controllers/Frontend/KyHome/KyHomeUnitTrait.php     modified: new_src/app/Http/Controllers/Frontend/KyHome/KyHomeWordFilterTrait.php 复制代码 可以通过 git checkout -- filename来撤销修改 git checkout -- new_src/app/Http/Controllers/Frontend/KyHome/KyHomeWordFilterTrait.php 再次查看文件状态发现选择的文件已经成功被撤销了。 复制代码 $ git status On branch test_git Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory)     modified: new_src/app/Http/Controllers/Frontend/KyHome/KyHomeUnitTrait.php      复制代码 如果想将多个文件一次性撤销可以用 git checkout -- . 上面是 未添加到暂存区的撤销 下面是添加到暂存区的 复制代码 $ git status On branch test_git Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: new_src/app/Http/Controllers/Frontend/KyHome/KyHomeApp.php modified: new_src/app/Http/Controllers/Frontend/KyHome/KyHomeComment.php 复制代码 复制代码 $ git add -A $ git status On branch test_git Changes to be committed: 已经添加暂存区了 (use "git reset HEAD ..." to unstage) modified: new_src/app/Http/Controllers/Frontend/KyHome/KyHomeApp.php modified: new_src/app/Http/Controllers/Frontend/KyHome/KyHomeComment.php 复制代码 从暂存区撤销 $ git reset HEAD new_src/app/Http/Controllers/Frontend/KyHome/KyHomeApp.php Unstaged changes after reset: M new_src/app/Http/Controllers/Frontend/KyHome/KyHomeApp.php 如果想一次性将所有暂存区文件撤销回来,还是上面的命令,不过不用加文件路径。 $ git reset HEAD Unstaged changes after reset: M new_src/app/Http/Controllers/Frontend/KyHome/KyHomeApp.php M new_src/app/Http/Controllers/Frontend/KyHome/KyHomeComment.php 二.git commit之后 如果当commit提交后想撤销的话,这就需要revert命令。git revert 命令是撤销某次操作,而在此次操作之前和之后的提交记录都会保留。 先修改了几个文件然后commit 再用git log查看提交记录。 commit 2842c8065322085c31fb7b8207b6296047c4ea3 Author: songguojun [email protected] Date: Sat Apr 28 11:21:30 2018 +0800 add content 然后使用revert 后面跟上git提交的commitid git revert 2842c8065322085c31fb7b8207b6296047c4ea3 复制代码 Revert "add content" This reverts commit 2842c8065ffe2085c31fb7b8207b6296047c4ea3. Please enter the commit message for your changes. Lines starting with '#' will be ignored, and an empty message aborts the commit. On branch test_git Changes to be committed: modified: new_src/app/Http/Controllers/Frontend/KyHome/KyHomeApp.php modified: new_src/app/Http/Controllers/Frontend/KyHome/KyHomeComment.php 复制代码 然后在推送到远端更新远程仓库代码,修改的文件就撤销回来了。注意的是revert奇数次生效,偶数次又回到之前的修改状态。比如一个文件内容是a,那么修改为ab,revert后文件变成了a,如果在revert后文件又还原成ab了。 还有就是如果想回到之前某个版本,可以用reset命令,可以回退到某次提交,那该提交之后的提交都会回滚,不过这种覆盖是不可逆的,之前的提交记录都没有了。所以平时开发中尽量注意,避免使用reset。 用法: git reset --hard commit_id –hard – 强制将缓存区和工作目录都同步到你指定的提交 git reset --hard fdeb212a5418cc8e31f32d63cf197550297468ec HEAD is now at fdeb212 增加mysql端口配置 然后在提交到远端覆盖。
Read More ~

Ubuntu修改时区和更新时间

1)先查看当前系统时间 root@ubuntu:/# date -R 2)运行tzselect 选择亚洲 Asia,确认之后选择中国(China),最后选择北京(Beijing) 3)复制文件到/etc目录下 cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 4)更新时间 sudo ntpdate time.windows.com 5)修改时间以后,修改硬件CMOS的时间 sudo hwclock –systohc
Read More ~